Пример #1
0
  @Test
  public void testReadMessageHead() throws UnsupportedEncodingException {
    String request = "GET / HTTP/1.1";
    BufferedReader bufferedReader = new BufferedReader(new StringReader(request));
    HashMap state = new HashMap();
    RequestHandler requestHandler = new RequestHandler(bufferedReader, state);
    requestHandler.parseHead(request);

    assertEquals("GET", requestHandler.getHttpMethod());

    BufferedReader newBufferedReader = new BufferedReader(new StringReader(request));
    requestHandler = new RequestHandler(newBufferedReader, state);
    request = "POST / HTTP/1.1";
    requestHandler.parseHead(request);

    assertEquals("POST", requestHandler.getHttpMethod());
  }
Пример #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"));
 }