hpack icon indicating copy to clipboard operation
hpack copied to clipboard

Standard headers are not correctly encoded

Open dilanSachi opened this issue 7 months ago • 0 comments

Describe the bug I am trying to encode several headers and my implementation is as follows.

ByteArrayOutputStream out = new ByteArrayOutputStream();
Encoder encoder = new Encoder(maxHeaderTableSize);
encoder.encodeHeader(out, "content-type".getBytes(), "application/json".getBytes(), sensitive);
encoder.encodeHeader(out, "user-agent".getBytes(), "wso2".getBytes(), sensitive);
encoder.encodeHeader(out, ":path".getBytes(), "/hello".getBytes(), sensitive);
encoder.encodeHeader(out, ":method".getBytes(), "GET".getBytes(), sensitive);

However, as i understood, the headers :path and :method are not getting encoded correctly. When I use the netty encoder, i get correctly encoded headers.

DefaultHttp2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder((name, value) -> false, true);
Http2Headers http2Headers = new DefaultHttp2Headers();
http2Headers.add("content-type", "application/json");
http2Headers.add("user-agent", "wso2");
http2Headers.path("/hello");
http2Headers.method("POST");

ByteBuf buf = Unpooled.buffer();
encoder.encodeHeaders(3, http2Headers, buf);

See the following output.

Netty encoded header values - 44062F68656C6C6F835F106170706C69636174696F6E2F6A736F6E7A0477736F32
hpack encoded header values - 0f108b1d75d0620d263d4c7441ea0f2b83f0838b04856272d141ff82

dilanSachi avatar Jul 03 '24 09:07 dilanSachi