diff --git a/src/be/jeffcheasey88/peeratcode/routes/Leaderboard.java b/src/be/jeffcheasey88/peeratcode/routes/Leaderboard.java index 457dc58..d9fe611 100644 --- a/src/be/jeffcheasey88/peeratcode/routes/Leaderboard.java +++ b/src/be/jeffcheasey88/peeratcode/routes/Leaderboard.java @@ -27,8 +27,8 @@ public class Leaderboard implements Response { public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception { HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *"); SortedSet allPlayers = databaseRepo.getAllPlayerForLeaderboard(); + JSONArray playersJSON = new JSONArray(); if (allPlayers != null) { - JSONArray playersJSON = new JSONArray(); for (Player player : allPlayers) { JSONObject playerJSON = new JSONObject(); playerJSON.put("pseudo", player.getPseudo()); @@ -39,8 +39,8 @@ public class Leaderboard implements Response { playerJSON.put("tries", player.getTotalTries()); playersJSON.add(playerJSON); } - writer.write(playersJSON.toJSONString()); } + writer.write(playersJSON.toJSONString()); writer.flush(); writer.close(); } diff --git a/src/be/jeffcheasey88/peeratcode/webserver/HttpUtil.java b/src/be/jeffcheasey88/peeratcode/webserver/HttpUtil.java index ddcf466..a49dd95 100644 --- a/src/be/jeffcheasey88/peeratcode/webserver/HttpUtil.java +++ b/src/be/jeffcheasey88/peeratcode/webserver/HttpUtil.java @@ -58,9 +58,11 @@ public class HttpUtil { String line; String key = null; while(((line = reader.readLine()) != null) && (line.length() > 0)){ - if(key != null) continue; Matcher matcher = AUTORIZATION.matcher(line); - if(matcher.matches()) key = matcher.group(1); + if(matcher.matches()){ + key = matcher.group(1); + break; + } } return key; }