| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/hpack_decoder.h" | 5 #include "net/spdy/hpack_decoder.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "net/spdy/hpack_encoder.h" | 13 #include "net/spdy/hpack_encoder.h" |
| 14 #include "net/spdy/hpack_input_stream.h" | 14 #include "net/spdy/hpack_input_stream.h" |
| 15 #include "net/spdy/hpack_output_stream.h" | 15 #include "net/spdy/hpack_output_stream.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 namespace test { | 21 namespace test { |
| 22 | 22 |
| 23 using base::StringPiece; | 23 using base::StringPiece; |
| 24 using std::string; | 24 using std::string; |
| 25 | 25 |
| 26 class HpackDecoderPeer { | 26 class HpackDecoderPeer { |
| 27 public: | 27 public: |
| 28 explicit HpackDecoderPeer(HpackDecoder* decoder) | 28 explicit HpackDecoderPeer(HpackDecoder* decoder) : decoder_(decoder) {} |
| 29 : decoder_(decoder) {} | |
| 30 | 29 |
| 31 void HandleHeaderRepresentation(StringPiece name, StringPiece value) { | 30 void HandleHeaderRepresentation(StringPiece name, StringPiece value) { |
| 32 decoder_->HandleHeaderRepresentation(name, value); | 31 decoder_->HandleHeaderRepresentation(name, value); |
| 33 } | 32 } |
| 34 bool DecodeNextName(HpackInputStream* in, StringPiece* out) { | 33 bool DecodeNextName(HpackInputStream* in, StringPiece* out) { |
| 35 return decoder_->DecodeNextName(in, out); | 34 return decoder_->DecodeNextName(in, out); |
| 36 } | 35 } |
| 37 const HpackHeaderTable& header_table() { | 36 const HpackHeaderTable& header_table() { return decoder_->header_table_; } |
| 38 return decoder_->header_table_; | 37 void set_cookie_name(string name) { decoder_->cookie_name_ = name; } |
| 39 } | 38 string cookie_name() { return decoder_->cookie_name_; } |
| 40 void set_cookie_name(string name) { | 39 void set_cookie_value(string value) { decoder_->cookie_value_ = value; } |
| 41 decoder_->cookie_name_ = name; | 40 string cookie_value() { return decoder_->cookie_value_; } |
| 42 } | |
| 43 string cookie_name() { | |
| 44 return decoder_->cookie_name_; | |
| 45 } | |
| 46 void set_cookie_value(string value) { | |
| 47 decoder_->cookie_value_ = value; | |
| 48 } | |
| 49 string cookie_value() { | |
| 50 return decoder_->cookie_value_; | |
| 51 } | |
| 52 const std::map<string, string>& decoded_block() const { | 41 const std::map<string, string>& decoded_block() const { |
| 53 return decoder_->decoded_block_; | 42 return decoder_->decoded_block_; |
| 54 } | 43 } |
| 55 const string& headers_block_buffer() const { | 44 const string& headers_block_buffer() const { |
| 56 return decoder_->headers_block_buffer_; | 45 return decoder_->headers_block_buffer_; |
| 57 } | 46 } |
| 58 | 47 |
| 59 private: | 48 private: |
| 60 HpackDecoder* decoder_; | 49 HpackDecoder* decoder_; |
| 61 }; | 50 }; |
| 62 | 51 |
| 63 } // namespace test | 52 } // namespace test |
| 64 | 53 |
| 65 namespace { | 54 namespace { |
| 66 | 55 |
| 67 using base::StringPiece; | 56 using base::StringPiece; |
| 68 using std::string; | 57 using std::string; |
| 69 | 58 |
| 70 using testing::ElementsAre; | 59 using testing::ElementsAre; |
| 71 using testing::Pair; | 60 using testing::Pair; |
| 72 | 61 |
| 73 const size_t kLiteralBound = 1024; | 62 const size_t kLiteralBound = 1024; |
| 74 | 63 |
| 75 class HpackDecoderTest : public ::testing::Test { | 64 class HpackDecoderTest : public ::testing::Test { |
| 76 protected: | 65 protected: |
| 77 HpackDecoderTest() | 66 HpackDecoderTest() |
| 78 : decoder_(ObtainHpackHuffmanTable()), | 67 : decoder_(ObtainHpackHuffmanTable()), decoder_peer_(&decoder_) {} |
| 79 decoder_peer_(&decoder_) {} | |
| 80 | 68 |
| 81 bool DecodeHeaderBlock(StringPiece str) { | 69 bool DecodeHeaderBlock(StringPiece str) { |
| 82 return decoder_.HandleControlFrameHeadersData(0, str.data(), str.size()) && | 70 return decoder_.HandleControlFrameHeadersData(0, str.data(), str.size()) && |
| 83 decoder_.HandleControlFrameHeadersComplete(0); | 71 decoder_.HandleControlFrameHeadersComplete(0); |
| 84 } | 72 } |
| 85 const std::map<string, string>& decoded_block() const { | 73 const std::map<string, string>& decoded_block() const { |
| 86 // TODO(jgraettinger): HpackDecoderTest should implement | 74 // TODO(jgraettinger): HpackDecoderTest should implement |
| 87 // SpdyHeadersHandlerInterface, and collect headers for examination. | 75 // SpdyHeadersHandlerInterface, and collect headers for examination. |
| 88 return decoder_peer_.decoded_block(); | 76 return decoder_peer_.decoded_block(); |
| 89 } | 77 } |
| 90 // TODO(jgraettinger): Eliminate uses of this in tests below. Prefer | 78 // TODO(jgraettinger): Eliminate uses of this in tests below. Prefer |
| 91 // DecodeHeaderBlock(). | 79 // DecodeHeaderBlock(). |
| 92 const std::map<string, string>& DecodeUniqueHeaderSet(StringPiece str) { | 80 const std::map<string, string>& DecodeUniqueHeaderSet(StringPiece str) { |
| 93 EXPECT_TRUE(DecodeHeaderBlock(str)); | 81 EXPECT_TRUE(DecodeHeaderBlock(str)); |
| 94 return decoded_block(); | 82 return decoded_block(); |
| 95 } | 83 } |
| 96 | 84 |
| 97 HpackDecoder decoder_; | 85 HpackDecoder decoder_; |
| 98 test::HpackDecoderPeer decoder_peer_; | 86 test::HpackDecoderPeer decoder_peer_; |
| 99 }; | 87 }; |
| 100 | 88 |
| 101 TEST_F(HpackDecoderTest, HandleControlFrameHeadersData) { | 89 TEST_F(HpackDecoderTest, HandleControlFrameHeadersData) { |
| 102 // Strings under threshold are concatenated in the buffer. | 90 // Strings under threshold are concatenated in the buffer. |
| 103 EXPECT_TRUE(decoder_.HandleControlFrameHeadersData( | 91 EXPECT_TRUE( |
| 104 0, "small string one", 16)); | 92 decoder_.HandleControlFrameHeadersData(0, "small string one", 16)); |
| 105 EXPECT_TRUE(decoder_.HandleControlFrameHeadersData( | 93 EXPECT_TRUE( |
| 106 0, "small string two", 16)); | 94 decoder_.HandleControlFrameHeadersData(0, "small string two", 16)); |
| 107 // A string which would push the buffer over the threshold is refused. | 95 // A string which would push the buffer over the threshold is refused. |
| 108 EXPECT_FALSE(decoder_.HandleControlFrameHeadersData( | 96 EXPECT_FALSE(decoder_.HandleControlFrameHeadersData( |
| 109 0, "fails", kMaxDecodeBufferSize - 32 + 1)); | 97 0, "fails", kMaxDecodeBufferSize - 32 + 1)); |
| 110 | 98 |
| 111 EXPECT_EQ(decoder_peer_.headers_block_buffer(), | 99 EXPECT_EQ(decoder_peer_.headers_block_buffer(), |
| 112 "small string onesmall string two"); | 100 "small string onesmall string two"); |
| 113 } | 101 } |
| 114 | 102 |
| 115 TEST_F(HpackDecoderTest, HandleControlFrameHeadersComplete) { | 103 TEST_F(HpackDecoderTest, HandleControlFrameHeadersComplete) { |
| 116 // Decode a block which toggles two static headers into the reference set. | 104 // Decode a block which toggles two static headers into the reference set. |
| 117 EXPECT_TRUE(DecodeHeaderBlock("\x82\x86")); | 105 EXPECT_TRUE(DecodeHeaderBlock("\x82\x86")); |
| 118 | 106 |
| 119 decoder_peer_.set_cookie_name("CooKie"); | 107 decoder_peer_.set_cookie_name("CooKie"); |
| 120 decoder_peer_.set_cookie_value("foobar=baz"); | 108 decoder_peer_.set_cookie_value("foobar=baz"); |
| 121 | 109 |
| 122 // Headers in the reference set should be emitted. | 110 // Headers in the reference set should be emitted. |
| 123 // Incremental cookie buffer should be emitted and cleared. | 111 // Incremental cookie buffer should be emitted and cleared. |
| 124 decoder_.HandleControlFrameHeadersData(0, NULL, 0); | 112 decoder_.HandleControlFrameHeadersData(0, NULL, 0); |
| 125 decoder_.HandleControlFrameHeadersComplete(0); | 113 decoder_.HandleControlFrameHeadersComplete(0); |
| 126 | 114 |
| 127 EXPECT_THAT(decoded_block(), ElementsAre( | 115 EXPECT_THAT(decoded_block(), |
| 128 Pair(":method", "GET"), | 116 ElementsAre(Pair(":method", "GET"), |
| 129 Pair(":path", "/index.html"), | 117 Pair(":path", "/index.html"), |
| 130 Pair("CooKie", "foobar=baz"))); | 118 Pair("CooKie", "foobar=baz"))); |
| 131 | 119 |
| 132 EXPECT_EQ(decoder_peer_.cookie_name(), ""); | 120 EXPECT_EQ(decoder_peer_.cookie_name(), ""); |
| 133 EXPECT_EQ(decoder_peer_.cookie_value(), ""); | 121 EXPECT_EQ(decoder_peer_.cookie_value(), ""); |
| 134 } | 122 } |
| 135 | 123 |
| 136 TEST_F(HpackDecoderTest, HandleHeaderRepresentation) { | 124 TEST_F(HpackDecoderTest, HandleHeaderRepresentation) { |
| 137 // Casing of first Cookie is retained, but all instances are joined. | 125 // Casing of first Cookie is retained, but all instances are joined. |
| 138 decoder_peer_.HandleHeaderRepresentation("cOOkie", " part 1"); | 126 decoder_peer_.HandleHeaderRepresentation("cOOkie", " part 1"); |
| 139 decoder_peer_.HandleHeaderRepresentation("cookie", "part 2 "); | 127 decoder_peer_.HandleHeaderRepresentation("cookie", "part 2 "); |
| 140 decoder_peer_.HandleHeaderRepresentation("cookie", "part3"); | 128 decoder_peer_.HandleHeaderRepresentation("cookie", "part3"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 156 decoder_peer_.HandleHeaderRepresentation("empty-joined", "foo"); | 144 decoder_peer_.HandleHeaderRepresentation("empty-joined", "foo"); |
| 157 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); | 145 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); |
| 158 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); | 146 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); |
| 159 | 147 |
| 160 // Non-contiguous cookie crumb. | 148 // Non-contiguous cookie crumb. |
| 161 decoder_peer_.HandleHeaderRepresentation("Cookie", " fin!"); | 149 decoder_peer_.HandleHeaderRepresentation("Cookie", " fin!"); |
| 162 | 150 |
| 163 // Finish and emit all headers. | 151 // Finish and emit all headers. |
| 164 decoder_.HandleControlFrameHeadersComplete(0); | 152 decoder_.HandleControlFrameHeadersComplete(0); |
| 165 | 153 |
| 166 EXPECT_THAT(decoded_block(), ElementsAre( | 154 EXPECT_THAT(decoded_block(), |
| 167 Pair("cOOkie", " part 1; part 2 ; part3; fin!"), | 155 ElementsAre(Pair("cOOkie", " part 1; part 2 ; part3; fin!"), |
| 168 Pair("empty", ""), | 156 Pair("empty", ""), |
| 169 Pair("empty-joined", string("\0foo\0\0", 6)), | 157 Pair("empty-joined", string("\0foo\0\0", 6)), |
| 170 Pair("joineD", string("value 1\0value 2", 15)), | 158 Pair("joineD", string("value 1\0value 2", 15)), |
| 171 Pair("joined", "not joined"), | 159 Pair("joined", "not joined"), |
| 172 Pair("passed-through", string("foo\0baz", 7)))); | 160 Pair("passed-through", string("foo\0baz", 7)))); |
| 173 } | 161 } |
| 174 | 162 |
| 175 // Decoding an encoded name with a valid string literal should work. | 163 // Decoding an encoded name with a valid string literal should work. |
| 176 TEST_F(HpackDecoderTest, DecodeNextNameLiteral) { | 164 TEST_F(HpackDecoderTest, DecodeNextNameLiteral) { |
| 177 HpackInputStream input_stream(kLiteralBound, StringPiece("\x00\x04name", 6)); | 165 HpackInputStream input_stream(kLiteralBound, StringPiece("\x00\x04name", 6)); |
| 178 | 166 |
| 179 StringPiece string_piece; | 167 StringPiece string_piece; |
| 180 EXPECT_TRUE(decoder_peer_.DecodeNextName(&input_stream, &string_piece)); | 168 EXPECT_TRUE(decoder_peer_.DecodeNextName(&input_stream, &string_piece)); |
| 181 EXPECT_EQ("name", string_piece); | 169 EXPECT_EQ("name", string_piece); |
| 182 EXPECT_FALSE(input_stream.HasMoreData()); | 170 EXPECT_FALSE(input_stream.HasMoreData()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 213 } | 201 } |
| 214 | 202 |
| 215 // Decoding an indexed header should toggle the index's presence in | 203 // Decoding an indexed header should toggle the index's presence in |
| 216 // the reference set, making a copy of static table entries if | 204 // the reference set, making a copy of static table entries if |
| 217 // necessary. It should also emit the header if toggled on (and only | 205 // necessary. It should also emit the header if toggled on (and only |
| 218 // as many times as it was toggled on). | 206 // as many times as it was toggled on). |
| 219 TEST_F(HpackDecoderTest, IndexedHeaderBasic) { | 207 TEST_F(HpackDecoderTest, IndexedHeaderBasic) { |
| 220 // Toggle on static table entry #2 (and make a copy at index #1), | 208 // Toggle on static table entry #2 (and make a copy at index #1), |
| 221 // then toggle on static table entry #5 (which is now #6 because of | 209 // then toggle on static table entry #5 (which is now #6 because of |
| 222 // the copy of #2). | 210 // the copy of #2). |
| 223 std::map<string, string> header_set1 = | 211 std::map<string, string> header_set1 = DecodeUniqueHeaderSet("\x82\x86"); |
| 224 DecodeUniqueHeaderSet("\x82\x86"); | |
| 225 std::map<string, string> expected_header_set1; | 212 std::map<string, string> expected_header_set1; |
| 226 expected_header_set1[":method"] = "GET"; | 213 expected_header_set1[":method"] = "GET"; |
| 227 expected_header_set1[":path"] = "/index.html"; | 214 expected_header_set1[":path"] = "/index.html"; |
| 228 EXPECT_EQ(expected_header_set1, header_set1); | 215 EXPECT_EQ(expected_header_set1, header_set1); |
| 229 | 216 |
| 230 std::map<string, string> expected_header_set2; | 217 std::map<string, string> expected_header_set2; |
| 231 expected_header_set2[":path"] = "/index.html"; | 218 expected_header_set2[":path"] = "/index.html"; |
| 232 // Toggle off the copy of static table entry #5. | 219 // Toggle off the copy of static table entry #5. |
| 233 std::map<string, string> header_set2 = | 220 std::map<string, string> header_set2 = DecodeUniqueHeaderSet("\x82"); |
| 234 DecodeUniqueHeaderSet("\x82"); | |
| 235 EXPECT_EQ(expected_header_set2, header_set2); | 221 EXPECT_EQ(expected_header_set2, header_set2); |
| 236 } | 222 } |
| 237 | 223 |
| 238 // Test a too-large indexed header. | 224 // Test a too-large indexed header. |
| 239 TEST_F(HpackDecoderTest, InvalidIndexedHeader) { | 225 TEST_F(HpackDecoderTest, InvalidIndexedHeader) { |
| 240 // High-bit set, and a prefix of one more than the number of static entries. | 226 // High-bit set, and a prefix of one more than the number of static entries. |
| 241 EXPECT_FALSE(DecodeHeaderBlock(StringPiece("\xbd", 1))); | 227 EXPECT_FALSE(DecodeHeaderBlock(StringPiece("\xbd", 1))); |
| 242 } | 228 } |
| 243 | 229 |
| 244 TEST_F(HpackDecoderTest, ContextUpdateMaximumSize) { | 230 TEST_F(HpackDecoderTest, ContextUpdateMaximumSize) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 271 | 257 |
| 272 output_stream.TakeString(&input); | 258 output_stream.TakeString(&input); |
| 273 EXPECT_FALSE(DecodeHeaderBlock(StringPiece(input))); | 259 EXPECT_FALSE(DecodeHeaderBlock(StringPiece(input))); |
| 274 EXPECT_EQ(kDefaultHeaderTableSizeSetting, | 260 EXPECT_EQ(kDefaultHeaderTableSizeSetting, |
| 275 decoder_peer_.header_table().max_size()); | 261 decoder_peer_.header_table().max_size()); |
| 276 } | 262 } |
| 277 } | 263 } |
| 278 | 264 |
| 279 TEST_F(HpackDecoderTest, ContextUpdateClearReferenceSet) { | 265 TEST_F(HpackDecoderTest, ContextUpdateClearReferenceSet) { |
| 280 // Toggle on a couple of headers. | 266 // Toggle on a couple of headers. |
| 281 std::map<string, string> header_set1 = | 267 std::map<string, string> header_set1 = DecodeUniqueHeaderSet("\x82\x86"); |
| 282 DecodeUniqueHeaderSet("\x82\x86"); | |
| 283 std::map<string, string> expected_header_set1; | 268 std::map<string, string> expected_header_set1; |
| 284 expected_header_set1[":method"] = "GET"; | 269 expected_header_set1[":method"] = "GET"; |
| 285 expected_header_set1[":path"] = "/index.html"; | 270 expected_header_set1[":path"] = "/index.html"; |
| 286 EXPECT_EQ(expected_header_set1, header_set1); | 271 EXPECT_EQ(expected_header_set1, header_set1); |
| 287 | 272 |
| 288 // Send a context update to clear the reference set. | 273 // Send a context update to clear the reference set. |
| 289 std::map<string, string> header_set2 = | 274 std::map<string, string> header_set2 = DecodeUniqueHeaderSet("\x80\x80"); |
| 290 DecodeUniqueHeaderSet("\x80\x80"); | |
| 291 std::map<string, string> expected_header_set2; | 275 std::map<string, string> expected_header_set2; |
| 292 EXPECT_EQ(expected_header_set2, header_set2); | 276 EXPECT_EQ(expected_header_set2, header_set2); |
| 293 } | 277 } |
| 294 | 278 |
| 295 // Decoding two valid encoded literal headers with no indexing should | 279 // Decoding two valid encoded literal headers with no indexing should |
| 296 // work. | 280 // work. |
| 297 TEST_F(HpackDecoderTest, LiteralHeaderNoIndexing) { | 281 TEST_F(HpackDecoderTest, LiteralHeaderNoIndexing) { |
| 298 // First header with indexed name, second header with string literal | 282 // First header with indexed name, second header with string literal |
| 299 // name. | 283 // name. |
| 300 std::map<string, string> header_set = | 284 std::map<string, string> header_set = DecodeUniqueHeaderSet( |
| 301 DecodeUniqueHeaderSet( | 285 "\x44\x0c/sample/path\x40\x06:path2\x0e/sample/path/2"); |
| 302 "\x44\x0c/sample/path\x40\x06:path2\x0e/sample/path/2"); | |
| 303 | 286 |
| 304 std::map<string, string> expected_header_set; | 287 std::map<string, string> expected_header_set; |
| 305 expected_header_set[":path"] = "/sample/path"; | 288 expected_header_set[":path"] = "/sample/path"; |
| 306 expected_header_set[":path2"] = "/sample/path/2"; | 289 expected_header_set[":path2"] = "/sample/path/2"; |
| 307 EXPECT_EQ(expected_header_set, header_set); | 290 EXPECT_EQ(expected_header_set, header_set); |
| 308 } | 291 } |
| 309 | 292 |
| 310 // Decoding two valid encoded literal headers with incremental | 293 // Decoding two valid encoded literal headers with incremental |
| 311 // indexing and string literal names should work and add the headers | 294 // indexing and string literal names should work and add the headers |
| 312 // to the reference set. | 295 // to the reference set. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 TEST_F(HpackDecoderTest, BasicE21) { | 327 TEST_F(HpackDecoderTest, BasicE21) { |
| 345 HpackEncoder encoder(ObtainHpackHuffmanTable()); | 328 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
| 346 | 329 |
| 347 std::map<string, string> expected_header_set; | 330 std::map<string, string> expected_header_set; |
| 348 expected_header_set[":method"] = "GET"; | 331 expected_header_set[":method"] = "GET"; |
| 349 expected_header_set[":scheme"] = "http"; | 332 expected_header_set[":scheme"] = "http"; |
| 350 expected_header_set[":path"] = "/"; | 333 expected_header_set[":path"] = "/"; |
| 351 expected_header_set[":authority"] = "www.example.com"; | 334 expected_header_set[":authority"] = "www.example.com"; |
| 352 | 335 |
| 353 string encoded_header_set; | 336 string encoded_header_set; |
| 354 EXPECT_TRUE(encoder.EncodeHeaderSet( | 337 EXPECT_TRUE( |
| 355 expected_header_set, &encoded_header_set)); | 338 encoder.EncodeHeaderSet(expected_header_set, &encoded_header_set)); |
| 356 | 339 |
| 357 EXPECT_TRUE(DecodeHeaderBlock(encoded_header_set)); | 340 EXPECT_TRUE(DecodeHeaderBlock(encoded_header_set)); |
| 358 EXPECT_EQ(expected_header_set, decoded_block()); | 341 EXPECT_EQ(expected_header_set, decoded_block()); |
| 359 } | 342 } |
| 360 | 343 |
| 361 TEST_F(HpackDecoderTest, SectionD3RequestHuffmanExamples) { | 344 TEST_F(HpackDecoderTest, SectionD3RequestHuffmanExamples) { |
| 362 std::map<string, string> header_set; | 345 std::map<string, string> header_set; |
| 363 | 346 |
| 364 // 82 | == Indexed - Add == | 347 // 82 | == Indexed - Add == |
| 365 // | idx = 2 | 348 // | idx = 2 |
| 366 // | -> :method: GET | 349 // | -> :method: GET |
| 367 // 87 | == Indexed - Add == | 350 // 87 | == Indexed - Add == |
| 368 // | idx = 7 | 351 // | idx = 7 |
| 369 // | -> :scheme: http | 352 // | -> :scheme: http |
| 370 // 86 | == Indexed - Add == | 353 // 86 | == Indexed - Add == |
| 371 // | idx = 6 | 354 // | idx = 6 |
| 372 // | -> :path: / | 355 // | -> :path: / |
| 373 // 04 | == Literal indexed == | 356 // 04 | == Literal indexed == |
| 374 // | Indexed name (idx = 4) | 357 // | Indexed name (idx = 4) |
| 375 // | :authority | 358 // | :authority |
| 376 // 8b | Literal value (len = 15) | 359 // 8b | Literal value (len = 15) |
| 377 // | Huffman encoded: | 360 // | Huffman encoded: |
| 378 // db6d 883e 68d1 cb12 25ba 7f | .m..h...%.. | 361 // db6d 883e 68d1 cb12 25ba 7f | .m..h...%.. |
| 379 // | Decoded: | 362 // | Decoded: |
| 380 // | www.example.com | 363 // | www.example.com |
| 381 // | -> :authority: www.example.com | 364 // | -> :authority: www.example.com |
| 382 char first[] = | 365 char first[] = |
| 383 "\x82\x87\x86\x04\x8b\xdb\x6d\x88\x3e\x68\xd1\xcb\x12\x25\xba\x7f"; | 366 "\x82\x87\x86\x04\x8b\xdb\x6d\x88\x3e\x68\xd1\xcb\x12\x25\xba\x7f"; |
| 384 header_set = DecodeUniqueHeaderSet(StringPiece(first, arraysize(first)-1)); | 367 header_set = DecodeUniqueHeaderSet(StringPiece(first, arraysize(first) - 1)); |
| 385 | 368 |
| 386 // TODO(jgraettinger): Create HpackEncodingContext and | 369 // TODO(jgraettinger): Create HpackEncodingContext and |
| 387 // HpackDecoder peers, and inspect the header table here. | 370 // HpackDecoder peers, and inspect the header table here. |
| 388 EXPECT_THAT(header_set, ElementsAre( | 371 EXPECT_THAT(header_set, |
| 389 Pair(":authority", "www.example.com"), | 372 ElementsAre(Pair(":authority", "www.example.com"), |
| 390 Pair(":method", "GET"), | 373 Pair(":method", "GET"), |
| 391 Pair(":path", "/"), | 374 Pair(":path", "/"), |
| 392 Pair(":scheme", "http"))); | 375 Pair(":scheme", "http"))); |
| 393 | 376 |
| 394 // 1b | == Literal indexed == | 377 // 1b | == Literal indexed == |
| 395 // | Indexed name (idx = 27) | 378 // | Indexed name (idx = 27) |
| 396 // | cache-control | 379 // | cache-control |
| 397 // 86 | Literal value (len = 8) | 380 // 86 | Literal value (len = 8) |
| 398 // | Huffman encoded: | 381 // | Huffman encoded: |
| 399 // 6365 4a13 98ff | ceJ... | 382 // 6365 4a13 98ff | ceJ... |
| 400 // | Decoded: | 383 // | Decoded: |
| 401 // | no-cache | 384 // | no-cache |
| 402 // | -> cache-control: no-cache | 385 // | -> cache-control: no-cache |
| 403 char second[] = "\x1b\x86\x63\x65\x4a\x13\x98\xff"; | 386 char second[] = "\x1b\x86\x63\x65\x4a\x13\x98\xff"; |
| 404 header_set = DecodeUniqueHeaderSet(StringPiece(second, arraysize(second)-1)); | 387 header_set = |
| 388 DecodeUniqueHeaderSet(StringPiece(second, arraysize(second) - 1)); |
| 405 | 389 |
| 406 EXPECT_THAT(header_set, ElementsAre( | 390 EXPECT_THAT(header_set, |
| 407 Pair(":authority", "www.example.com"), | 391 ElementsAre(Pair(":authority", "www.example.com"), |
| 408 Pair(":method", "GET"), | 392 Pair(":method", "GET"), |
| 409 Pair(":path", "/"), | 393 Pair(":path", "/"), |
| 410 Pair(":scheme", "http"), | 394 Pair(":scheme", "http"), |
| 411 Pair("cache-control", "no-cache"))); | 395 Pair("cache-control", "no-cache"))); |
| 412 | 396 |
| 413 // 8080 | == Empty reference set == | 397 // 8080 | == Empty reference set == |
| 414 // | idx = 0 | 398 // | idx = 0 |
| 415 // | flag = 1 | 399 // | flag = 1 |
| 416 // 85 | == Indexed - Add == | 400 // 85 | == Indexed - Add == |
| 417 // | idx = 5 | 401 // | idx = 5 |
| 418 // | -> :method: GET | 402 // | -> :method: GET |
| 419 // 8c | == Indexed - Add == | 403 // 8c | == Indexed - Add == |
| 420 // | idx = 12 | 404 // | idx = 12 |
| 421 // | -> :scheme: https | 405 // | -> :scheme: https |
| (...skipping 11 matching lines...) Expand all Loading... |
| 433 // | custom-key | 417 // | custom-key |
| 434 // 89 | Literal value (len = 12) | 418 // 89 | Literal value (len = 12) |
| 435 // | Huffman encoded: | 419 // | Huffman encoded: |
| 436 // 4eb0 8b74 979a 17a8 ff | N..t..... | 420 // 4eb0 8b74 979a 17a8 ff | N..t..... |
| 437 // | Decoded: | 421 // | Decoded: |
| 438 // | custom-value | 422 // | custom-value |
| 439 // | -> custom-key: custom-value | 423 // | -> custom-key: custom-value |
| 440 char third[] = | 424 char third[] = |
| 441 "\x80\x80\x85\x8c\x8b\x84\x00\x88\x4e\xb0\x8b\x74\x97\x90\xfa\x7f\x89" | 425 "\x80\x80\x85\x8c\x8b\x84\x00\x88\x4e\xb0\x8b\x74\x97\x90\xfa\x7f\x89" |
| 442 "\x4e\xb0\x8b\x74\x97\x9a\x17\xa8\xff"; | 426 "\x4e\xb0\x8b\x74\x97\x9a\x17\xa8\xff"; |
| 443 header_set = DecodeUniqueHeaderSet(StringPiece(third, arraysize(third)-1)); | 427 header_set = DecodeUniqueHeaderSet(StringPiece(third, arraysize(third) - 1)); |
| 444 | 428 |
| 445 EXPECT_THAT(header_set, ElementsAre( | 429 EXPECT_THAT(header_set, |
| 446 Pair(":authority", "www.example.com"), | 430 ElementsAre(Pair(":authority", "www.example.com"), |
| 447 Pair(":method", "GET"), | 431 Pair(":method", "GET"), |
| 448 Pair(":path", "/index.html"), | 432 Pair(":path", "/index.html"), |
| 449 Pair(":scheme", "https"), | 433 Pair(":scheme", "https"), |
| 450 Pair("custom-key", "custom-value"))); | 434 Pair("custom-key", "custom-value"))); |
| 451 } | 435 } |
| 452 | 436 |
| 453 TEST_F(HpackDecoderTest, SectionD5ResponseHuffmanExamples) { | 437 TEST_F(HpackDecoderTest, SectionD5ResponseHuffmanExamples) { |
| 454 std::map<string, string> header_set; | 438 std::map<string, string> header_set; |
| 455 decoder_.ApplyHeaderTableSizeSetting(256); | 439 decoder_.ApplyHeaderTableSizeSetting(256); |
| 456 | 440 |
| 457 // 08 | == Literal indexed == | 441 // 08 | == Literal indexed == |
| 458 // | Indexed name (idx = 8) | 442 // | Indexed name (idx = 8) |
| 459 // | :status | 443 // | :status |
| 460 // 82 | Literal value (len = 3) | 444 // 82 | Literal value (len = 3) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 // ce31 743d 801b 6db1 07cd 1a39 6244 b74f | .1t=..m....9bD.O | 476 // ce31 743d 801b 6db1 07cd 1a39 6244 b74f | .1t=..m....9bD.O |
| 493 // | Decoded: | 477 // | Decoded: |
| 494 // | https://www.example.com | 478 // | https://www.example.com |
| 495 // | -> location: https://www.e | 479 // | -> location: https://www.e |
| 496 // | xample.com | 480 // | xample.com |
| 497 char first[] = | 481 char first[] = |
| 498 "\x08\x82\x98\xa7\x18\x85\x73\xd5\xcd\x11\x1f\x22\x98\xef\x6b" | 482 "\x08\x82\x98\xa7\x18\x85\x73\xd5\xcd\x11\x1f\x22\x98\xef\x6b" |
| 499 "\x3a\x7a\x0e\x6e\x8f\xa2\x63\xd0\x72\x9a\x6e\x83\x97\xd8\x69\xbd\x87" | 483 "\x3a\x7a\x0e\x6e\x8f\xa2\x63\xd0\x72\x9a\x6e\x83\x97\xd8\x69\xbd\x87" |
| 500 "\x37\x47\xbb\xbf\xc7\x30\x90\xce\x31\x74\x3d\x80\x1b\x6d\xb1\x07\xcd" | 484 "\x37\x47\xbb\xbf\xc7\x30\x90\xce\x31\x74\x3d\x80\x1b\x6d\xb1\x07\xcd" |
| 501 "\x1a\x39\x62\x44\xb7\x4f"; | 485 "\x1a\x39\x62\x44\xb7\x4f"; |
| 502 header_set = DecodeUniqueHeaderSet(StringPiece(first, arraysize(first)-1)); | 486 header_set = DecodeUniqueHeaderSet(StringPiece(first, arraysize(first) - 1)); |
| 503 | 487 |
| 504 EXPECT_THAT(header_set, ElementsAre( | 488 EXPECT_THAT(header_set, |
| 505 Pair(":status", "302"), | 489 ElementsAre(Pair(":status", "302"), |
| 506 Pair("cache-control", "private"), | 490 Pair("cache-control", "private"), |
| 507 Pair("date", "Mon, 21 Oct 2013 20:13:21 GMT"), | 491 Pair("date", "Mon, 21 Oct 2013 20:13:21 GMT"), |
| 508 Pair("location", "https://www.example.com"))); | 492 Pair("location", "https://www.example.com"))); |
| 509 | 493 |
| 510 // 8c | == Indexed - Add == | 494 // 8c | == Indexed - Add == |
| 511 // | idx = 12 | 495 // | idx = 12 |
| 512 // | - evict: :status: 302 | 496 // | - evict: :status: 302 |
| 513 // | -> :status: 200 | 497 // | -> :status: 200 |
| 514 char second[] = "\x8c"; | 498 char second[] = "\x8c"; |
| 515 header_set = DecodeUniqueHeaderSet(StringPiece(second, arraysize(second)-1)); | 499 header_set = |
| 500 DecodeUniqueHeaderSet(StringPiece(second, arraysize(second) - 1)); |
| 516 | 501 |
| 517 EXPECT_THAT(header_set, ElementsAre( | 502 EXPECT_THAT(header_set, |
| 518 Pair(":status", "200"), | 503 ElementsAre(Pair(":status", "200"), |
| 519 Pair("cache-control", "private"), | 504 Pair("cache-control", "private"), |
| 520 Pair("date", "Mon, 21 Oct 2013 20:13:21 GMT"), | 505 Pair("date", "Mon, 21 Oct 2013 20:13:21 GMT"), |
| 521 Pair("location", "https://www.example.com"))); | 506 Pair("location", "https://www.example.com"))); |
| 522 | 507 |
| 523 // 84 | == Indexed - Remove == | 508 // 84 | == Indexed - Remove == |
| 524 // | idx = 4 | 509 // | idx = 4 |
| 525 // | -> cache-control: private | 510 // | -> cache-control: private |
| 526 // 84 | == Indexed - Add == | 511 // 84 | == Indexed - Add == |
| 527 // | idx = 4 | 512 // | idx = 4 |
| 528 // | -> cache-control: private | 513 // | -> cache-control: private |
| 529 // 03 | == Literal indexed == | 514 // 03 | == Literal indexed == |
| 530 // | Indexed name (idx = 3) | 515 // | Indexed name (idx = 3) |
| 531 // | date | 516 // | date |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 // | -> set-cookie: foo=ASDJKHQ | 569 // | -> set-cookie: foo=ASDJKHQ |
| 585 // | KBZXOQWEOPIUAXQWEOIU; ma | 570 // | KBZXOQWEOPIUAXQWEOIU; ma |
| 586 // | x-age=3600; version=1 | 571 // | x-age=3600; version=1 |
| 587 char third[] = | 572 char third[] = |
| 588 "\x84\x84\x03\x98\xef\x6b\x3a\x7a\x0e\x6e\x8f\xa2\x63\xd0\x72" | 573 "\x84\x84\x03\x98\xef\x6b\x3a\x7a\x0e\x6e\x8f\xa2\x63\xd0\x72" |
| 589 "\x9a\x6e\x83\x97\xd8\x69\xbd\x87\x3f\x47\xbb\xbf\xc7\x1d\x83\xcb\xd5" | 574 "\x9a\x6e\x83\x97\xd8\x69\xbd\x87\x3f\x47\xbb\xbf\xc7\x1d\x83\xcb\xd5" |
| 590 "\x4e\x84\x84\x83\x83\x3a\xb3\xc5\xad\xb7\x7f\x87\x6f\xc7\xfb\xf7\xfd" | 575 "\x4e\x84\x84\x83\x83\x3a\xb3\xc5\xad\xb7\x7f\x87\x6f\xc7\xfb\xf7\xfd" |
| 591 "\xbf\xbe\xbf\xf3\xf7\xf4\xfb\x7e\xbb\xbe\x9f\x5f\x87\xe3\x7f\xef\xed" | 576 "\xbf\xbe\xbf\xf3\xf7\xf4\xfb\x7e\xbb\xbe\x9f\x5f\x87\xe3\x7f\xef\xed" |
| 592 "\xfa\xee\xfa\x7c\x3f\x1d\x5d\x1a\x23\xce\x54\x64\x36\xcd\x49\x4b\xd5" | 577 "\xfa\xee\xfa\x7c\x3f\x1d\x5d\x1a\x23\xce\x54\x64\x36\xcd\x49\x4b\xd5" |
| 593 "\xd1\xcc\x5f\x05\x35\x96\x9b"; | 578 "\xd1\xcc\x5f\x05\x35\x96\x9b"; |
| 594 header_set = DecodeUniqueHeaderSet(StringPiece(third, arraysize(third)-1)); | 579 header_set = DecodeUniqueHeaderSet(StringPiece(third, arraysize(third) - 1)); |
| 595 | 580 |
| 596 EXPECT_THAT(header_set, ElementsAre( | 581 EXPECT_THAT(header_set, |
| 597 Pair(":status", "200"), | 582 ElementsAre(Pair(":status", "200"), |
| 598 Pair("cache-control", "private"), | 583 Pair("cache-control", "private"), |
| 599 Pair("content-encoding", "gzip"), | 584 Pair("content-encoding", "gzip"), |
| 600 Pair("date", "Mon, 21 Oct 2013 20:13:22 GMT"), | 585 Pair("date", "Mon, 21 Oct 2013 20:13:22 GMT"), |
| 601 Pair("location", "https://www.example.com"), | 586 Pair("location", "https://www.example.com"), |
| 602 Pair("set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" | 587 Pair("set-cookie", |
| 603 " max-age=3600; version=1"))); | 588 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" |
| 589 " max-age=3600; version=1"))); |
| 604 } | 590 } |
| 605 | 591 |
| 606 } // namespace | 592 } // namespace |
| 607 | 593 |
| 608 } // namespace net | 594 } // namespace net |
| OLD | NEW |