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/hpack_decoder.h" | 5 #include "net/spdy/hpack/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" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 decoder_peer_.HandleHeaderRepresentation("empty-joined", "foo"); | 129 decoder_peer_.HandleHeaderRepresentation("empty-joined", "foo"); |
130 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); | 130 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); |
131 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); | 131 decoder_peer_.HandleHeaderRepresentation("empty-joined", ""); |
132 | 132 |
133 // Non-contiguous cookie crumb. | 133 // Non-contiguous cookie crumb. |
134 decoder_peer_.HandleHeaderRepresentation("cookie", " fin!"); | 134 decoder_peer_.HandleHeaderRepresentation("cookie", " fin!"); |
135 | 135 |
136 // Finish and emit all headers. | 136 // Finish and emit all headers. |
137 decoder_.HandleControlFrameHeadersComplete(0, nullptr); | 137 decoder_.HandleControlFrameHeadersComplete(0, nullptr); |
138 | 138 |
| 139 // Resulting decoded headers are in the same order as input. |
139 EXPECT_THAT(decoded_block(), | 140 EXPECT_THAT(decoded_block(), |
140 ElementsAre(Pair("cookie", " part 1; part 2 ; part3; fin!"), | 141 ElementsAre(Pair("cookie", " part 1; part 2 ; part3; fin!"), |
| 142 Pair("passed-through", StringPiece("foo\0baz", 7)), |
| 143 Pair("joined", "not joined"), |
| 144 Pair("joineD", StringPiece("value 1\0value 2", 15)), |
141 Pair("empty", ""), | 145 Pair("empty", ""), |
142 Pair("empty-joined", string("\0foo\0\0", 6)), | 146 Pair("empty-joined", StringPiece("\0foo\0\0", 6)))); |
143 Pair("joineD", string("value 1\0value 2", 15)), | |
144 Pair("joined", "not joined"), | |
145 Pair("passed-through", string("foo\0baz", 7)))); | |
146 } | 147 } |
147 | 148 |
148 // Decoding an encoded name with a valid string literal should work. | 149 // Decoding an encoded name with a valid string literal should work. |
149 TEST_F(HpackDecoderTest, DecodeNextNameLiteral) { | 150 TEST_F(HpackDecoderTest, DecodeNextNameLiteral) { |
150 HpackInputStream input_stream(kLiteralBound, StringPiece("\x00\x04name", 6)); | 151 HpackInputStream input_stream(kLiteralBound, StringPiece("\x00\x04name", 6)); |
151 | 152 |
152 StringPiece string_piece; | 153 StringPiece string_piece; |
153 EXPECT_TRUE(decoder_peer_.DecodeNextName(&input_stream, &string_piece)); | 154 EXPECT_TRUE(decoder_peer_.DecodeNextName(&input_stream, &string_piece)); |
154 EXPECT_EQ("name", string_piece); | 155 EXPECT_EQ("name", string_piece); |
155 EXPECT_FALSE(input_stream.HasMoreData()); | 156 EXPECT_FALSE(input_stream.HasMoreData()); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // | Decoded: | 381 // | Decoded: |
381 // | www.example.com | 382 // | www.example.com |
382 // | -> :authority: www.example.com | 383 // | -> :authority: www.example.com |
383 string first = a2b_hex( | 384 string first = a2b_hex( |
384 "828684418cf1e3c2e5f23a6ba0ab90f4" | 385 "828684418cf1e3c2e5f23a6ba0ab90f4" |
385 "ff"); | 386 "ff"); |
386 header_set = DecodeBlockExpectingSuccess(first); | 387 header_set = DecodeBlockExpectingSuccess(first); |
387 | 388 |
388 EXPECT_THAT( | 389 EXPECT_THAT( |
389 header_set, | 390 header_set, |
390 ElementsAre(Pair(":authority", "www.example.com"), Pair(":method", "GET"), | 391 ElementsAre(Pair(":method", "GET"), Pair(":scheme", "http"), |
391 Pair(":path", "/"), Pair(":scheme", "http"))); | 392 Pair(":path", "/"), Pair(":authority", "www.example.com"))); |
392 | 393 |
393 expectEntry(62, 57, ":authority", "www.example.com"); | 394 expectEntry(62, 57, ":authority", "www.example.com"); |
394 EXPECT_EQ(57u, decoder_peer_.header_table()->size()); | 395 EXPECT_EQ(57u, decoder_peer_.header_table()->size()); |
395 | 396 |
396 // 82 | == Indexed - Add == | 397 // 82 | == Indexed - Add == |
397 // | idx = 2 | 398 // | idx = 2 |
398 // | -> :method: GET | 399 // | -> :method: GET |
399 // 86 | == Indexed - Add == | 400 // 86 | == Indexed - Add == |
400 // | idx = 6 | 401 // | idx = 6 |
401 // | -> :scheme: http | 402 // | -> :scheme: http |
(...skipping 11 matching lines...) Expand all Loading... |
413 // a8eb 1064 9cbf | ...d.. | 414 // a8eb 1064 9cbf | ...d.. |
414 // | Decoded: | 415 // | Decoded: |
415 // | no-cache | 416 // | no-cache |
416 // | -> cache-control: no-cache | 417 // | -> cache-control: no-cache |
417 | 418 |
418 string second = a2b_hex("828684be5886a8eb10649cbf"); | 419 string second = a2b_hex("828684be5886a8eb10649cbf"); |
419 header_set = DecodeBlockExpectingSuccess(second); | 420 header_set = DecodeBlockExpectingSuccess(second); |
420 | 421 |
421 EXPECT_THAT( | 422 EXPECT_THAT( |
422 header_set, | 423 header_set, |
423 ElementsAre(Pair(":authority", "www.example.com"), Pair(":method", "GET"), | 424 ElementsAre(Pair(":method", "GET"), Pair(":scheme", "http"), |
424 Pair(":path", "/"), Pair(":scheme", "http"), | 425 Pair(":path", "/"), Pair(":authority", "www.example.com"), |
425 Pair("cache-control", "no-cache"))); | 426 Pair("cache-control", "no-cache"))); |
426 | 427 |
427 expectEntry(62, 53, "cache-control", "no-cache"); | 428 expectEntry(62, 53, "cache-control", "no-cache"); |
428 expectEntry(63, 57, ":authority", "www.example.com"); | 429 expectEntry(63, 57, ":authority", "www.example.com"); |
429 EXPECT_EQ(110u, decoder_peer_.header_table()->size()); | 430 EXPECT_EQ(110u, decoder_peer_.header_table()->size()); |
430 | 431 |
431 // 82 | == Indexed - Add == | 432 // 82 | == Indexed - Add == |
432 // | idx = 2 | 433 // | idx = 2 |
433 // | -> :method: GET | 434 // | -> :method: GET |
434 // 87 | == Indexed - Add == | 435 // 87 | == Indexed - Add == |
(...skipping 15 matching lines...) Expand all Loading... |
450 // | Huffman encoded: | 451 // | Huffman encoded: |
451 // 25a8 49e9 5bb8 e8b4 bf | %.I.[.... | 452 // 25a8 49e9 5bb8 e8b4 bf | %.I.[.... |
452 // | Decoded: | 453 // | Decoded: |
453 // | custom-value | 454 // | custom-value |
454 // | -> custom-key: custom-value | 455 // | -> custom-key: custom-value |
455 string third = a2b_hex( | 456 string third = a2b_hex( |
456 "828785bf408825a849e95ba97d7f89" | 457 "828785bf408825a849e95ba97d7f89" |
457 "25a849e95bb8e8b4bf"); | 458 "25a849e95bb8e8b4bf"); |
458 header_set = DecodeBlockExpectingSuccess(third); | 459 header_set = DecodeBlockExpectingSuccess(third); |
459 | 460 |
460 EXPECT_THAT( | 461 EXPECT_THAT(header_set, |
461 header_set, | 462 ElementsAre(Pair(":method", "GET"), Pair(":scheme", "https"), |
462 ElementsAre(Pair(":authority", "www.example.com"), Pair(":method", "GET"), | 463 Pair(":path", "/index.html"), |
463 Pair(":path", "/index.html"), Pair(":scheme", "https"), | 464 Pair(":authority", "www.example.com"), |
464 Pair("custom-key", "custom-value"))); | 465 Pair("custom-key", "custom-value"))); |
465 | 466 |
466 expectEntry(62, 54, "custom-key", "custom-value"); | 467 expectEntry(62, 54, "custom-key", "custom-value"); |
467 expectEntry(63, 53, "cache-control", "no-cache"); | 468 expectEntry(63, 53, "cache-control", "no-cache"); |
468 expectEntry(64, 57, ":authority", "www.example.com"); | 469 expectEntry(64, 57, ":authority", "www.example.com"); |
469 EXPECT_EQ(164u, decoder_peer_.header_table()->size()); | 470 EXPECT_EQ(164u, decoder_peer_.header_table()->size()); |
470 } | 471 } |
471 | 472 |
472 TEST_F(HpackDecoderTest, SectionD6ResponseHuffmanExamples) { | 473 TEST_F(HpackDecoderTest, SectionD6ResponseHuffmanExamples) { |
473 SpdyHeaderBlock header_set; | 474 SpdyHeaderBlock header_set; |
474 decoder_.ApplyHeaderTableSizeSetting(256); | 475 decoder_.ApplyHeaderTableSizeSetting(256); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 "88c16196d07abe941054d444a8200595" | 628 "88c16196d07abe941054d444a8200595" |
628 "040b8166e084a62d1bffc05a839bd9ab" | 629 "040b8166e084a62d1bffc05a839bd9ab" |
629 "77ad94e7821dd7f2e6c7b335dfdfcd5b" | 630 "77ad94e7821dd7f2e6c7b335dfdfcd5b" |
630 "3960d5af27087f3672c1ab270fb5291f" | 631 "3960d5af27087f3672c1ab270fb5291f" |
631 "9587316065c003ed4ee5b1063d5007"); | 632 "9587316065c003ed4ee5b1063d5007"); |
632 header_set = DecodeBlockExpectingSuccess(third); | 633 header_set = DecodeBlockExpectingSuccess(third); |
633 | 634 |
634 EXPECT_THAT( | 635 EXPECT_THAT( |
635 header_set, | 636 header_set, |
636 ElementsAre(Pair(":status", "200"), Pair("cache-control", "private"), | 637 ElementsAre(Pair(":status", "200"), Pair("cache-control", "private"), |
637 Pair("content-encoding", "gzip"), | |
638 Pair("date", "Mon, 21 Oct 2013 20:13:22 GMT"), | 638 Pair("date", "Mon, 21 Oct 2013 20:13:22 GMT"), |
639 Pair("location", "https://www.example.com"), | 639 Pair("location", "https://www.example.com"), |
| 640 Pair("content-encoding", "gzip"), |
640 Pair("set-cookie", | 641 Pair("set-cookie", |
641 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" | 642 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" |
642 " max-age=3600; version=1"))); | 643 " max-age=3600; version=1"))); |
643 | 644 |
644 expectEntry(62, 98, "set-cookie", | 645 expectEntry(62, 98, "set-cookie", |
645 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" | 646 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" |
646 " max-age=3600; version=1"); | 647 " max-age=3600; version=1"); |
647 expectEntry(63, 52, "content-encoding", "gzip"); | 648 expectEntry(63, 52, "content-encoding", "gzip"); |
648 expectEntry(64, 65, "date", "Mon, 21 Oct 2013 20:13:22 GMT"); | 649 expectEntry(64, 65, "date", "Mon, 21 Oct 2013 20:13:22 GMT"); |
649 EXPECT_EQ(215u, decoder_peer_.header_table()->size()); | 650 EXPECT_EQ(215u, decoder_peer_.header_table()->size()); |
650 } | 651 } |
651 | 652 |
652 } // namespace | 653 } // namespace |
653 } // namespace test | 654 } // namespace test |
654 } // namespace net | 655 } // namespace net |
OLD | NEW |