Skip to content

Commit

Permalink
Update to h2-16, hpack-10.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Dec 15, 2014
1 parent 09637b6 commit 0ad37ce
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 238 deletions.
4 changes: 2 additions & 2 deletions okcurl/src/main/java/com/squareup/okhttp/curl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.internal.http.StatusLine;
import com.squareup.okhttp.internal.spdy.Http20Draft15;
import com.squareup.okhttp.internal.spdy.Http20Draft16;

import io.airlift.command.Arguments;
import io.airlift.command.Command;
Expand Down Expand Up @@ -266,7 +266,7 @@ private static HostnameVerifier createInsecureHostnameVerifier() {
}

private static void enableHttp2FrameLogging() {
Logger logger = Logger.getLogger(Http20Draft15.class.getName() + "$FrameLogger");
Logger logger = Logger.getLogger(Http20Draft16.class.getName() + "$FrameLogger");
logger.setLevel(Level.FINE);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINE);
Expand Down
3 changes: 0 additions & 3 deletions okhttp-hpacktests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ initialize them, you must run:
git submodule init
git submodule update

When new interop tests are available, you should update
HpackDecodeInteropGoodTest#GOOD_INTEROP_TESTS with the directory name.

TODO
----

Expand Down
3 changes: 1 addition & 2 deletions okhttp-hpacktests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.squareup.okhttp</groupId>
<artifactId>parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>okhttp-hpacktests</artifactId>
Expand Down Expand Up @@ -37,7 +37,6 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected static Collection<Story[]> createStories(String[] interopTests)
}

private final Buffer bytesIn = new Buffer();
private final HpackDraft09.Reader hpackReader = new HpackDraft09.Reader(4096, bytesIn);
private final HpackDraft10.Reader hpackReader = new HpackDraft10.Reader(4096, bytesIn);

private final Story story;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Collection<Story[]> getStories() throws Exception {
}

private Buffer bytesOut = new Buffer();
private HpackDraft09.Writer hpackWriter = new HpackDraft09.Writer(bytesOut);
private HpackDraft10.Writer hpackWriter = new HpackDraft10.Writer(bytesOut);

public HpackRoundTripTest(Story story) {
super(story);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.concurrent.TimeUnit;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import static org.junit.Assert.assertEquals;

public class HttpOverHttp20Draft15Test extends HttpOverSpdyTest {
public class HttpOverHttp20Draft16Test extends HttpOverSpdyTest {

public HttpOverHttp20Draft15Test() {
public HttpOverHttp20Draft16Test() {
super(Protocol.HTTP_2);
this.hostHeader = ":authority";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class HpackDraft09Test {
public class HpackDraft10Test {

private final Buffer bytesIn = new Buffer();
private HpackDraft09.Reader hpackReader;
private HpackDraft10.Reader hpackReader;
private Buffer bytesOut = new Buffer();
private HpackDraft09.Writer hpackWriter;
private HpackDraft10.Writer hpackWriter;

@Before public void reset() {
hpackReader = newReader(bytesIn);
hpackWriter = new HpackDraft09.Writer(bytesOut);
hpackWriter = new HpackDraft10.Writer(bytesOut);
}

/**
* Variable-length quantity special cases strings which are longer than 127
* bytes. Values such as cookies can be 4KiB, and should be possible to send.
*
* <p> http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-09#section-6.1
* <p> http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10#section-5.2
*/
@Test public void largeHeaderValue() throws IOException {
char[] value = new char[4096];
Expand Down Expand Up @@ -72,7 +72,7 @@ public class HpackDraft09Test {
bytesIn.writeByte(0x0d); // Literal value (len = 13)
bytesIn.writeUtf8("custom-header");

hpackReader.maxHeaderTableByteCountSetting(1);
hpackReader.headerTableSizeSetting(1);
hpackReader.readHeaders();

assertEquals(0, hpackReader.headerCount);
Expand Down Expand Up @@ -104,15 +104,15 @@ public class HpackDraft09Test {
bytesIn.writeUtf8("custom-header");

// Set to only support 110 bytes (enough for 2 headers).
hpackReader.maxHeaderTableByteCountSetting(110);
hpackReader.headerTableSizeSetting(110);
hpackReader.readHeaders();

assertEquals(2, hpackReader.headerCount);

Header entry = hpackReader.headerTable[headerTableLength() - 1];
Header entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, "custom-bar", "custom-header", 55);

entry = hpackReader.headerTable[headerTableLength() - 2];
entry = hpackReader.dynamicTable[headerTableLength() - 2];
checkEntry(entry, "custom-baz", "custom-header", 55);

// Once a header field is decoded and added to the reconstructed header
Expand All @@ -125,7 +125,7 @@ public class HpackDraft09Test {
hpackReader.getAndResetHeaderList());

// Simulate receiving a small settings frame, that implies eviction.
hpackReader.maxHeaderTableByteCountSetting(55);
hpackReader.headerTableSizeSetting(55);
assertEquals(1, hpackReader.headerCount);
}

Expand All @@ -140,7 +140,7 @@ public class HpackDraft09Test {
bytesIn.writeUtf8("custom-header");
}

hpackReader.maxHeaderTableByteCountSetting(16384); // Lots of headers need more room!
hpackReader.headerTableSizeSetting(16384); // Lots of headers need more room!
hpackReader.readHeaders();

assertEquals(256, hpackReader.headerCount);
Expand All @@ -156,14 +156,14 @@ public class HpackDraft09Test {
hpackReader.readHeaders();

assertEquals(1, hpackReader.headerCount);
assertEquals(52, hpackReader.headerTableByteCount);
assertEquals(52, hpackReader.dynamicTableByteCount);

Header entry = hpackReader.headerTable[headerTableLength() - 1];
Header entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, ":path", "www.example.com", 52);
}

/**
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-09#appendix-D.2.1
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10#appendix-C.2.1
*/
@Test public void readLiteralHeaderFieldWithIndexing() throws IOException {
bytesIn.writeByte(0x40); // Literal indexed
Expand All @@ -176,16 +176,16 @@ public class HpackDraft09Test {
hpackReader.readHeaders();

assertEquals(1, hpackReader.headerCount);
assertEquals(55, hpackReader.headerTableByteCount);
assertEquals(55, hpackReader.dynamicTableByteCount);

Header entry = hpackReader.headerTable[headerTableLength() - 1];
Header entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, "custom-key", "custom-header", 55);

assertEquals(headerEntries("custom-key", "custom-header"), hpackReader.getAndResetHeaderList());
}

/**
* https://tools.ietf.org/html/draft-ietf-httpbis-header-compression-09#appendix-D.2.2
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10#appendix-C.2.2
*/
@Test public void literalHeaderFieldWithoutIndexingIndexedName() throws IOException {
List<Header> headerBlock = headerEntries(":path", "/sample/path");
Expand Down Expand Up @@ -260,9 +260,9 @@ public class HpackDraft09Test {
hpackReader.readHeaders();

assertEquals(0, hpackReader.headerCount);
assertEquals(0, hpackReader.headerTableByteCount);
assertEquals(0, hpackReader.dynamicTableByteCount);

assertEquals(null, hpackReader.headerTable[headerTableLength() - 1]);
assertEquals(null, hpackReader.dynamicTable[headerTableLength() - 1]);

assertEquals(headerEntries(":method", "GET"), hpackReader.getAndResetHeaderList());
}
Expand Down Expand Up @@ -309,14 +309,14 @@ public class HpackDraft09Test {
bytesIn.writeByte(0x20);
hpackReader.readHeaders();

assertEquals(0, hpackReader.maxHeaderTableByteCount());
assertEquals(0, hpackReader.maxDynamicTableByteCount());

bytesIn.writeByte(0x3f); // encode size 4096
bytesIn.writeByte(0xe1);
bytesIn.writeByte(0x1f);
hpackReader.readHeaders();

assertEquals(4096, hpackReader.maxHeaderTableByteCount());
assertEquals(4096, hpackReader.maxDynamicTableByteCount());
}

// Example taken from twitter/hpack DecoderTest.testIllegalHeaderTableSizeUpdate
Expand Down Expand Up @@ -347,13 +347,13 @@ public class HpackDraft09Test {
}

/**
* https://tools.ietf.org/html/draft-ietf-httpbis-header-compression-09#appendix-D.2.4
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10#appendix-C.2.4
*/
@Test public void readIndexedHeaderFieldFromStaticTableWithoutBuffering() throws IOException {
bytesIn.writeByte(0x82); // == Indexed - Add ==
// idx = 2 -> :method: GET

hpackReader.maxHeaderTableByteCountSetting(0); // SETTINGS_HEADER_TABLE_SIZE == 0
hpackReader.headerTableSizeSetting(0); // SETTINGS_HEADER_TABLE_SIZE == 0
hpackReader.readHeaders();

// Not buffered in header table.
Expand All @@ -363,7 +363,7 @@ public class HpackDraft09Test {
}

/**
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-09#appendix-D.2
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10#appendix-C.2
*/
@Test public void readRequestExamplesWithoutHuffman() throws IOException {
firstRequestWithoutHuffman();
Expand Down Expand Up @@ -396,11 +396,11 @@ private void checkReadFirstRequestWithoutHuffman() {
assertEquals(1, hpackReader.headerCount);

// [ 1] (s = 57) :authority: www.example.com
Header entry = hpackReader.headerTable[headerTableLength() - 1];
Header entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, ":authority", "www.example.com", 57);

// Table size: 57
assertEquals(57, hpackReader.headerTableByteCount);
assertEquals(57, hpackReader.dynamicTableByteCount);

// Decoded header list:
assertEquals(headerEntries(
Expand Down Expand Up @@ -429,15 +429,15 @@ private void checkReadSecondRequestWithoutHuffman() {
assertEquals(2, hpackReader.headerCount);

// [ 1] (s = 53) cache-control: no-cache
Header entry = hpackReader.headerTable[headerTableLength() - 2];
Header entry = hpackReader.dynamicTable[headerTableLength() - 2];
checkEntry(entry, "cache-control", "no-cache", 53);

// [ 2] (s = 57) :authority: www.example.com
entry = hpackReader.headerTable[headerTableLength() - 1];
entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, ":authority", "www.example.com", 57);

// Table size: 110
assertEquals(110, hpackReader.headerTableByteCount);
assertEquals(110, hpackReader.dynamicTableByteCount);

// Decoded header list:
assertEquals(headerEntries(
Expand Down Expand Up @@ -468,19 +468,19 @@ private void checkReadThirdRequestWithoutHuffman() {
assertEquals(3, hpackReader.headerCount);

// [ 1] (s = 54) custom-key: custom-value
Header entry = hpackReader.headerTable[headerTableLength() - 3];
Header entry = hpackReader.dynamicTable[headerTableLength() - 3];
checkEntry(entry, "custom-key", "custom-value", 54);

// [ 2] (s = 53) cache-control: no-cache
entry = hpackReader.headerTable[headerTableLength() - 2];
entry = hpackReader.dynamicTable[headerTableLength() - 2];
checkEntry(entry, "cache-control", "no-cache", 53);

// [ 3] (s = 57) :authority: www.example.com
entry = hpackReader.headerTable[headerTableLength() - 1];
entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, ":authority", "www.example.com", 57);

// Table size: 164
assertEquals(164, hpackReader.headerTableByteCount);
assertEquals(164, hpackReader.dynamicTableByteCount);

// Decoded header list:
assertEquals(headerEntries(
Expand All @@ -492,7 +492,7 @@ private void checkReadThirdRequestWithoutHuffman() {
}

/**
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-09#appendix-D.4
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10#appendix-C.4
*/
@Test public void readRequestExamplesWithHuffman() throws IOException {
firstRequestWithHuffman();
Expand Down Expand Up @@ -526,11 +526,11 @@ private void checkReadFirstRequestWithHuffman() {
assertEquals(1, hpackReader.headerCount);

// [ 1] (s = 57) :authority: www.example.com
Header entry = hpackReader.headerTable[headerTableLength() - 1];
Header entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, ":authority", "www.example.com", 57);

// Table size: 57
assertEquals(57, hpackReader.headerTableByteCount);
assertEquals(57, hpackReader.dynamicTableByteCount);

// Decoded header list:
assertEquals(headerEntries(
Expand Down Expand Up @@ -560,15 +560,15 @@ private void checkReadSecondRequestWithHuffman() {
assertEquals(2, hpackReader.headerCount);

// [ 1] (s = 53) cache-control: no-cache
Header entry = hpackReader.headerTable[headerTableLength() - 2];
Header entry = hpackReader.dynamicTable[headerTableLength() - 2];
checkEntry(entry, "cache-control", "no-cache", 53);

// [ 2] (s = 57) :authority: www.example.com
entry = hpackReader.headerTable[headerTableLength() - 1];
entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, ":authority", "www.example.com", 57);

// Table size: 110
assertEquals(110, hpackReader.headerTableByteCount);
assertEquals(110, hpackReader.dynamicTableByteCount);

// Decoded header list:
assertEquals(headerEntries(
Expand Down Expand Up @@ -601,19 +601,19 @@ private void checkReadThirdRequestWithHuffman() {
assertEquals(3, hpackReader.headerCount);

// [ 1] (s = 54) custom-key: custom-value
Header entry = hpackReader.headerTable[headerTableLength() - 3];
Header entry = hpackReader.dynamicTable[headerTableLength() - 3];
checkEntry(entry, "custom-key", "custom-value", 54);

// [ 2] (s = 53) cache-control: no-cache
entry = hpackReader.headerTable[headerTableLength() - 2];
entry = hpackReader.dynamicTable[headerTableLength() - 2];
checkEntry(entry, "cache-control", "no-cache", 53);

// [ 3] (s = 57) :authority: www.example.com
entry = hpackReader.headerTable[headerTableLength() - 1];
entry = hpackReader.dynamicTable[headerTableLength() - 1];
checkEntry(entry, ":authority", "www.example.com", 57);

// Table size: 164
assertEquals(164, hpackReader.headerTableByteCount);
assertEquals(164, hpackReader.dynamicTableByteCount);

// Decoded header list:
assertEquals(headerEntries(
Expand Down Expand Up @@ -692,8 +692,8 @@ private void checkReadThirdRequestWithHuffman() {
assertEquals(ByteString.EMPTY, newReader(byteStream(0)).readByteString());
}

private HpackDraft09.Reader newReader(Buffer source) {
return new HpackDraft09.Reader(4096, source);
private HpackDraft10.Reader newReader(Buffer source) {
return new HpackDraft10.Reader(4096, source);
}

private Buffer byteStream(int... bytes) {
Expand Down Expand Up @@ -721,6 +721,6 @@ private ByteString intArrayToByteArray(int[] bytes) {
}

private int headerTableLength() {
return hpackReader.headerTable.length;
return hpackReader.dynamicTable.length;
}
}
Loading

0 comments on commit 0ad37ce

Please sign in to comment.