Skip to content

Commit e0409fe

Browse files
committed
Revert "okhttp: Optimize HPACK to index :path"
This reverts commit 397d3e7.
1 parent cc0d1a8 commit e0409fe

2 files changed

Lines changed: 11 additions & 35 deletions

File tree

  • okhttp/third_party/okhttp

okhttp/third_party/okhttp/main/java/io/grpc/okhttp/internal/framed/Hpack.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,9 @@ void writeHeaders(List<io.grpc.okhttp.internal.framed.Header> headerBlock) throw
490490
writeByteString(name);
491491
writeByteString(value);
492492
insertIntoDynamicTable(header);
493-
} else if (name.startsWith(PSEUDO_PREFIX)
494-
&& !io.grpc.okhttp.internal.framed.Header.TARGET_AUTHORITY.equals(name)
495-
&& !io.grpc.okhttp.internal.framed.Header.TARGET_PATH.equals(name)) {
496-
// Allow :authority and :path pseudo headers to be indexed. Other pseudo headers are not
497-
// indexed.
498-
// This is a departure from the original Chrome-inspired behavior, as gRPC paths
499-
// (ServiceName/MethodName)
500-
// are stable and benefit from indexing.
493+
} else if (name.startsWith(PSEUDO_PREFIX) && !io.grpc.okhttp.internal.framed.Header.TARGET_AUTHORITY.equals(name)) {
494+
// Follow Chromes lead - only include the :authority pseudo header, but exclude all other
495+
// pseudo headers. Literal Header Field without Indexing - Indexed Name.
501496
writeInt(headerNameIndex, PREFIX_4_BITS, 0);
502497
writeByteString(value);
503498
} else {

okhttp/third_party/okhttp/test/java/io/grpc/okhttp/internal/framed/HpackTest.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,14 @@ public void readerEviction() throws IOException {
272272

273273
/**
274274
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-12#appendix-C.2.2
275-
*
276-
* <p>This test mimics the draft example which uses ":path", but since gRPC-Java now indexes
277-
* ":path" for performance, we use ":method" (with a non-static value like "PUT") to verify the
278-
* "Literal Header Field without Indexing - Indexed Name" representation.
279275
*/
280276
@Test public void literalHeaderFieldWithoutIndexingIndexedName() throws IOException {
281-
List<Header> headerBlock = headerEntries(":method", "PUT");
277+
List<Header> headerBlock = headerEntries(":path", "/sample/path");
282278

283-
bytesIn.writeByte(0x02); // == Literal not indexed ==
284-
// Indexed name (idx = 2) -> :method
285-
bytesIn.writeByte(0x03); // Literal value (len = 3)
286-
bytesIn.writeUtf8("PUT");
279+
bytesIn.writeByte(0x04); // == Literal not indexed ==
280+
// Indexed name (idx = 4) -> :path
281+
bytesIn.writeByte(0x0c); // Literal value (len = 12)
282+
bytesIn.writeUtf8("/sample/path");
287283

288284
hpackWriter.writeHeaders(headerBlock);
289285
assertEquals(bytesIn, bytesOut);
@@ -1108,29 +1104,14 @@ public void dynamicTableIndexedHeader() throws IOException {
11081104
}
11091105

11101106
@Test
1111-
public void pseudoHeaderIndexing() throws IOException {
1112-
// :method is not indexed (unless it's GET or POST, which are in the static table)
1107+
public void doNotIndexPseudoHeaders() throws IOException {
11131108
hpackWriter.writeHeaders(headerEntries(":method", "PUT"));
11141109
assertBytes(0x02, 3, 'P', 'U', 'T');
11151110
assertEquals(0, hpackWriter.dynamicTableHeaderCount);
11161111

1117-
// :path should now be indexed
1118-
hpackWriter.writeHeaders(headerEntries(":path", "/okhttp"));
1119-
assertBytes(0x44, 7, '/', 'o', 'k', 'h', 't', 't', 'p');
1120-
assertEquals(1, hpackWriter.dynamicTableHeaderCount);
1121-
// Second time should be an index
11221112
hpackWriter.writeHeaders(headerEntries(":path", "/okhttp"));
1123-
assertBytes(0xbe);
1124-
assertEquals(1, hpackWriter.dynamicTableHeaderCount);
1125-
1126-
// :authority should be indexed
1127-
hpackWriter.writeHeaders(headerEntries(":authority", "test.com"));
1128-
assertBytes(0x41, 8, 't', 'e', 's', 't', '.', 'c', 'o', 'm');
1129-
assertEquals(2, hpackWriter.dynamicTableHeaderCount);
1130-
// Second time should be an index
1131-
hpackWriter.writeHeaders(headerEntries(":authority", "test.com"));
1132-
assertBytes(0xbe);
1133-
assertEquals(2, hpackWriter.dynamicTableHeaderCount);
1113+
assertBytes(0x04, 7, '/', 'o', 'k', 'h', 't', 't', 'p');
1114+
assertEquals(0, hpackWriter.dynamicTableHeaderCount);
11341115
}
11351116

11361117
@Test

0 commit comments

Comments
 (0)