Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions java/org/apache/coyote/http2/HpackEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public boolean shouldUseHuffman(String header) {
private final HpackHeaderFunction hpackHeaderFunction;

HpackEncoder() {
this.hpackHeaderFunction = DEFAULT_HEADER_FUNCTION;
this(DEFAULT_HEADER_FUNCTION);
}

HpackEncoder(HpackHeaderFunction hpackHeaderFunction) {
this.hpackHeaderFunction = hpackHeaderFunction;
}

/**
Expand Down Expand Up @@ -398,7 +402,7 @@ int getPosition() {
}
}

private interface HpackHeaderFunction {
interface HpackHeaderFunction {
boolean shouldUseIndexing(String header, String value);

/**
Expand Down
21 changes: 18 additions & 3 deletions test/org/apache/coyote/http2/TestHpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@ public void testEncode() throws Exception {
headers.setValue(":status").setString("200");
headers.setValue("header2").setString("value2");
ByteBuffer output = ByteBuffer.allocate(512);
HpackEncoder encoder = new HpackEncoder();
HpackEncoder encoder = new HpackEncoder(new HpackEncoder.HpackHeaderFunction() {

@Override
public boolean shouldUseIndexing(String header, String value) {
return true;
}

@Override
public boolean shouldUseHuffman(String header, String value) {
return true;
}

@Override
public boolean shouldUseHuffman(String header) {
return true;
}
});
encoder.encode(headers, output);
output.flip();
// Size is supposed to be 33 without huffman, or 27 with it
// TODO: use the HpackHeaderFunction to enable huffman predictably
// Size is 27 with Huffman encoding
Assert.assertEquals(27, output.remaining());
output.clear();
encoder.encode(headers, output);
Expand Down