Package org.deftserver.util

Examples of org.deftserver.util.HttpRequestHelper


    assertTrue(requestOk);
  }

  @Test
  public void testHostVerification_exists_HTTP_1_1() {
    HttpRequestHelper helper = new HttpRequestHelper();
    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    boolean requestOk = HttpUtil.verifyRequest(request);
    assertTrue(requestOk);
  }
View Full Code Here


    assertTrue(requestOk);
  }

  @Test
  public void testHostVerification_nonExisting_HTTP_1_1() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.removeHeader("Host");
    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    boolean requestOk = HttpUtil.verifyRequest(request);
    assertFalse(requestOk);
  }
View Full Code Here

   * case-insensitive retrieval through {@link HttpRequest#getHeader(String)}.
   */
  @Test
  public void testOfConvertsHeaderKeysToLowerCase() {

    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addHeader("TESTKEY", "unimportant");
    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());

    assertFalse(request.getHeaders().containsKey("TESTKEY"));
    assertTrue(request.getHeaders().containsKey("testkey"));
  }
View Full Code Here

  @Test
  public void testOfMaintainsHeaderValueCase() {

    String expected = "vAlUe";

    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addHeader("TESTKEY", expected);
    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());

    String actual = request.getHeader("TESTKEY");
    assertEquals(expected, actual);
  }
View Full Code Here

  @Test
  public void testGetHeader() {

    String expected = "value";

    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addHeader("TESTKEY", expected);
    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());

    assertEquals(expected, request.getHeader("TESTKEY"));
    assertEquals(expected, request.getHeader("testkey"));
  }
View Full Code Here

public class HttpRequestTest {


  @Test
  public void testDeserializeHttpGetRequest() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addHeader("Host", "127.0.0.1:8080");
    helper.addHeader("User-Agent", "curl/7.19.5 (i386-apple-darwin10.0.0) libcurl/7.19.5 zlib/1.2.3");
    helper.addHeader("Accept", "*/*");
    ByteBuffer bb1 = helper.getRequestAsByteBuffer();

    helper = new HttpRequestHelper();
    helper.addHeader("Host", "127.0.0.1:8080");
    helper.addHeader("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; sv-SE; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
    helper.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    helper.addHeader("Accept-Language", "sv-se,sv;q=0.8,en-us;q=0.5,en;q=0.3");
    helper.addHeader("Accept-Encoding", "gzip,deflate");
    helper.addHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    helper.addHeader("Keep-Alive", "115");
    helper.addHeader("Connection", "keep-alve");
    ByteBuffer bb2 = helper.getRequestAsByteBuffer();

    HttpRequest request1 = HttpRequest.of(bb1);
    HttpRequest request2 = HttpRequest.of(bb2);

    assertEquals("GET / HTTP/1.1", request1.getRequestLine());
View Full Code Here

    assertEquals(3, ArrayUtil.dropFromEndWhile(fields2, "").length);
  }

  @Test
  public void testSingleGetParameter() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", "jim");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());

    assertEquals(1, request.getParameters().size());
    assertEquals("jim", request.getParameter("firstname"));
  }
View Full Code Here

    assertEquals("jim", request.getParameter("firstname"));
  }

  @Test
  public void testMultipleGetParameter() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", "jim");
    helper.addGetParameter("lastname", "petersson");
    helper.addGetParameter("city", "stockholm");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(3, getSize(params));
    assertEquals("jim", request.getParameter("firstname"));
    assertEquals("petersson", request.getParameter("lastname"));
View Full Code Here

  }


  @Test
  public void testSingleParameterWithoutValue() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", null);

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();
    assertEquals(0, getSize(params));
    assertEquals(null, request.getParameter("firstname"));
  }
View Full Code Here

    assertEquals(null, request.getParameter("firstname"));
  }

  @Test
  public void testMultipleParametersWithoutValue() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", null);
    helper.addGetParameter("lastName", "");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(0, getSize(params));
    assertEquals(null, request.getParameter("firstname"));
    assertEquals(null, request.getParameter("lastName"));
View Full Code Here

TOP

Related Classes of org.deftserver.util.HttpRequestHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.