Пример #1
0
  @Test
  public void testCachedPut() throws Exception {
    HttpFields header = new HttpFields();

    header.put("Connection", "Keep-Alive");
    header.put("tRansfer-EncOding", "CHUNKED");
    header.put("CONTENT-ENCODING", "gZIP");

    ByteBuffer buffer = BufferUtils.allocate(1024);
    BufferUtils.flipToFill(buffer);
    HttpGenerator.putTo(header, buffer);
    BufferUtils.flipToFlush(buffer, 0);
    String out = BufferUtils.toString(buffer).toLowerCase();

    Assert.assertThat(
        out,
        Matchers.containsString(
            (HttpHeader.CONNECTION + ": " + HttpHeaderValue.KEEP_ALIVE).toLowerCase()));
    Assert.assertThat(
        out,
        Matchers.containsString(
            (HttpHeader.TRANSFER_ENCODING + ": " + HttpHeaderValue.CHUNKED).toLowerCase()));
    Assert.assertThat(
        out,
        Matchers.containsString(
            (HttpHeader.CONTENT_ENCODING + ": " + HttpHeaderValue.GZIP).toLowerCase()));
  }
Пример #2
0
  @Test
  public void testCRLF() throws Exception {
    HttpFields header = new HttpFields();

    header.put("name0", "value\r\n0");
    header.put("name\r\n1", "value1");
    header.put("name:2", "value:\r\n2");

    ByteBuffer buffer = BufferUtils.allocate(1024);
    BufferUtils.flipToFill(buffer);
    HttpGenerator.putTo(header, buffer);
    BufferUtils.flipToFlush(buffer, 0);
    String out = BufferUtils.toString(buffer);
    assertThat(out, containsString("name0: value  0"));
    assertThat(out, containsString("name??1: value1"));
    assertThat(out, containsString("name?2: value:  2"));
  }
Пример #3
0
  @Test
  public void testPutTo() throws Exception {
    HttpFields header = new HttpFields();

    header.put("name0", "value0");
    header.put("name1", "value:A");
    header.add("name1", "value:B");
    header.add("name2", "");

    ByteBuffer buffer = BufferUtils.allocate(1024);
    BufferUtils.flipToFill(buffer);
    HttpGenerator.putTo(header, buffer);
    BufferUtils.flipToFlush(buffer, 0);
    String result = BufferUtils.toString(buffer);

    assertThat(result, Matchers.containsString("name0: value0"));
    assertThat(result, Matchers.containsString("name1: value:A"));
    assertThat(result, Matchers.containsString("name1: value:B"));
  }