private static void testLastResponseWithTrailingHeaderFragmented(
      byte[] content, int fragmentSize) {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
    int headerLength = 47;
    // split up the header
    for (int a = 0; a < headerLength; ) {
      int amount = fragmentSize;
      if (a + amount > headerLength) {
        amount = headerLength - a;
      }

      // if header is done it should produce a HttpRequest
      boolean headerDone = a + amount == headerLength;
      assertEquals(headerDone, ch.writeInbound(Unpooled.wrappedBuffer(content, a, amount)));
      a += amount;
    }

    ch.writeInbound(Unpooled.wrappedBuffer(content, headerLength, content.length - headerLength));
    HttpResponse res = ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
    assertThat(res.getStatus(), is(HttpResponseStatus.OK));

    LastHttpContent lastContent = ch.readInbound();
    assertThat(lastContent.content().isReadable(), is(false));
    HttpHeaders headers = lastContent.trailingHeaders();
    assertEquals(1, headers.names().size());
    List<String> values = headers.getAll("Set-Cookie");
    assertEquals(2, values.size());
    assertTrue(values.contains("t1=t1v1"));
    assertTrue(values.contains("t2=t2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT"));
    lastContent.release();

    assertThat(ch.finish(), is(false));
    assertThat(ch.readInbound(), is(nullValue()));
  }
  @Test
  public void testLastResponseWithTrailingHeader() {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
    ch.writeInbound(
        Unpooled.copiedBuffer(
            "HTTP/1.1 200 OK\r\n"
                + "Transfer-Encoding: chunked\r\n"
                + "\r\n"
                + "0\r\n"
                + "Set-Cookie: t1=t1v1\r\n"
                + "Set-Cookie: t2=t2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT\r\n"
                + "\r\n",
            CharsetUtil.US_ASCII));

    HttpResponse res = ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
    assertThat(res.getStatus(), is(HttpResponseStatus.OK));

    LastHttpContent lastContent = ch.readInbound();
    assertThat(lastContent.content().isReadable(), is(false));
    HttpHeaders headers = lastContent.trailingHeaders();
    assertEquals(1, headers.names().size());
    List<String> values = headers.getAll("Set-Cookie");
    assertEquals(2, values.size());
    assertTrue(values.contains("t1=t1v1"));
    assertTrue(values.contains("t2=t2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT"));
    lastContent.release();

    assertThat(ch.finish(), is(false));
    assertThat(ch.readInbound(), is(nullValue()));
  }