/** * Figures out the type of request and sends the data to the correct method to handle it. * * @param headers * @param in * @param out * @throws IOException */ private void parseRequest(List<String> headers, InputStream in, PrintStream out) throws IOException { // parse request if (headers.get(0).toUpperCase().startsWith("GET")) { parseGET(headers, out, in); } else if (headers.get(0).toUpperCase().startsWith("POST")) { parsePOST(headers, out, in); } else { System.out.println("Could not successfully parse request: " + headers); // This wasn't a well-formed request PrintWriter writer = new PrintWriter(new OutputStreamWriter(out), true); writer.println("HTTP/1.0 400 Bad Request\r\n\r\n"); writer.println( "<html><body>It seems like you made a bad request.<br />Please try again...and this time don't screw up.</html></body>"); writer.flush(); } }