Ejemplo n.º 1
0
  @Test
  public void testMapMultipleFields() {
    String request = "Host: localhost:5000\n" + "Connection: keep-alive\n";
    BufferedReader bufferedReader = new BufferedReader(new StringReader(request));
    HashMap state = new HashMap();
    RequestHandler requestHandler = new RequestHandler(bufferedReader, state);
    ArrayList<String> splitRequest = requestHandler.splitRequestByLine(request);
    Map testMap = new HashMap();
    testMap.put("Host", "localhost:5000");
    testMap.put("Connection", "keep-alive");
    requestHandler.mapFields(splitRequest);

    assertEquals(testMap, requestHandler.getHeaderFields());
  }
Ejemplo n.º 2
0
 @Test
 public void testParseRequest() throws UnsupportedEncodingException {
   String request =
       "GET / HTTP/1.1\n"
           + "Host: localhost:5000\n"
           + "Connection: keep-alive\n"
           + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n"
           + "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36\n"
           + "Accept-Encoding: gzip,deflate,sdch\n"
           + "Accept-Language: en-US,en;q=0.8\n"
           + "Cookie: textwrapon=false; wysiwyg=textarea";
   BufferedReader bufferedReader = new BufferedReader(new StringReader(request));
   HashMap state = new HashMap();
   RequestHandler requestHandler = new RequestHandler(bufferedReader, state);
   requestHandler.parseRequest(request);
   assertEquals("GET", requestHandler.getHttpMethod());
   assertEquals("/", requestHandler.getRoute());
   assertEquals("HTTP/1.1", requestHandler.getProtocol());
   assertEquals("localhost:5000", requestHandler.getHeaderFields().get("Host"));
 }