Пример #1
0
  @Test
  public void testParsesQueryString() throws IOException {
    String request = "GET /parameters?variable_1=Operators%20%3C HTTP/1.1";
    HashMap state = null;

    BufferedReader bufferedReader = new BufferedReader(new StringReader(request));
    RequestHandler requestHandler = new RequestHandler(bufferedReader, state);

    requestHandler.parseRoute("/parameters?variable_1=Operators%20%3C");

    assertEquals("/parameters", requestHandler.getRoute());
    assertEquals("variable_1=Operators%20%3C", requestHandler.getQueryString());

    requestHandler.parseQueryString(requestHandler.getQueryString());

    assertEquals("variable_1 = Operators <", new String(requestHandler.getBody()));
  }
Пример #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"));
 }