Compare commits
	
		
			No commits in common. "06912d0a772f11b992db297e9b312afc866722e0" and "e7578e3fc33047f73147ce989048fa68751b3c27" have entirely different histories.
		
	
	
		
			06912d0a77
			...
			e7578e3fc3
		
	
		
| @ -33,32 +33,12 @@ class CommunityHandler implements HttpHandler { | ||||
|         subJSON.put("permalink", sub.getPermalink()); | ||||
|         return subJSON; | ||||
|     } | ||||
|     private void sendResponse(HttpExchange t, String response) throws IOException { | ||||
|         System.out.println("response > "+response); | ||||
|         Headers headers = t.getResponseHeaders(); | ||||
|         headers.set("Content-Type", "application/json; charset=UTF-8"); | ||||
|         System.out.println(response.length()); | ||||
|         OutputStream os = t.getResponseBody(); | ||||
|         headers.add("Connection", "close"); | ||||
|         t.sendResponseHeaders(200, response.length()); | ||||
|         os.write(response.getBytes(StandardCharsets.UTF_8)); | ||||
|         os.close(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void handle(HttpExchange t) throws IOException { | ||||
|         System.out.println("request at > "+t.getRequestURI().toString()); | ||||
|         String[] pathArray = t.getRequestURI().toString().split("/", -1); | ||||
| 
 | ||||
|         JSONObject responseJSON = new JSONObject(); | ||||
|         JSONArray subsJSON = new JSONArray(); | ||||
| 
 | ||||
|         if (pathArray.length < 5 || pathArray[4].equals("")){ | ||||
|             responseJSON.put("error", "no subreddit specified"); | ||||
|             sendResponse(t, responseJSON.toString()); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         List<Submission> submissions = null; | ||||
|         try { | ||||
|             submissions = this.api.getSub(pathArray[4]); | ||||
| @ -67,6 +47,8 @@ class CommunityHandler implements HttpHandler { | ||||
|         } | ||||
|         assert submissions != null; | ||||
| 
 | ||||
|         JSONObject responseJSON = new JSONObject(); | ||||
|         JSONArray subsJSON = new JSONArray(); | ||||
|         if ( pathArray.length < 6 || pathArray[5].equals("") || pathArray[5].equals("random")) { | ||||
|             Random rand = new Random(); | ||||
|             subsJSON.put(subToJSON( | ||||
| @ -94,6 +76,16 @@ class CommunityHandler implements HttpHandler { | ||||
|             } | ||||
|         } | ||||
|         responseJSON.put("subs", subsJSON); | ||||
|         sendResponse(t, responseJSON.toString()); | ||||
|          | ||||
|         String response = responseJSON.toString(); | ||||
|         System.out.println("response > "+response); | ||||
|         Headers headers = t.getResponseHeaders(); | ||||
|         headers.set("Content-Type", "application/json; charset=UTF-8"); | ||||
|         System.out.println(response.length()); | ||||
|         OutputStream os = t.getResponseBody(); | ||||
|         headers.add("Connection", "close"); | ||||
|         t.sendResponseHeaders(200, response.length()); | ||||
|         os.write(response.getBytes(StandardCharsets.UTF_8)); | ||||
|         os.close(); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user