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_encoder.h" | 5 #include "net/spdy/hpack_encoder.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // 63: cookie: a=bb | 304 // 63: cookie: a=bb |
305 // 62: cookie: c=dd | 305 // 62: cookie: c=dd |
306 // Pass 2. | 306 // Pass 2. |
307 { | 307 { |
308 map<string, string> headers; | 308 map<string, string> headers; |
309 headers["key1"] = "value1"; | 309 headers["key1"] = "value1"; |
310 headers["key2"] = "value2"; | 310 headers["key2"] = "value2"; |
311 headers["cookie"] = "c=dd; e=ff"; | 311 headers["cookie"] = "c=dd; e=ff"; |
312 | 312 |
313 ExpectIndex(IndexOf(cookie_c_)); | 313 ExpectIndex(IndexOf(cookie_c_)); |
| 314 // key1 by index. |
| 315 ExpectIndex(65); |
| 316 // key2 by index. |
| 317 ExpectIndex(64); |
314 // This cookie evicts |key1| from the header table. | 318 // This cookie evicts |key1| from the header table. |
315 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff"); | 319 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff"); |
316 // |key1| is inserted to the header table, which evicts |key2|. | |
317 ExpectIndexedLiteral("key1", "value1"); | |
318 // |key2| is inserted to the header table, which evicts |cookie_a|. | |
319 ExpectIndexedLiteral("key2", "value2"); | |
320 | 320 |
321 CompareWithExpectedEncoding(headers); | 321 CompareWithExpectedEncoding(headers); |
322 } | 322 } |
323 // Header table is: | 323 // Header table is: |
324 // 65: cookie: c=dd | 324 // 65: key2: value2 |
325 // 64: cookie: e=ff | 325 // 64: cookie: a=bb |
326 // 63: key1: value1 | 326 // 63: cookie: c=dd |
327 // 62: key2: value2 | 327 // 62: cookie: e=ff |
328 // Pass 3. | 328 // Pass 3. |
329 { | 329 { |
330 map<string, string> headers; | 330 map<string, string> headers; |
331 headers["key1"] = "value1"; | 331 headers["key1"] = "value1"; |
332 headers["key3"] = "value3"; | 332 headers["key3"] = "value3"; |
333 headers["cookie"] = "e=ff"; | 333 headers["cookie"] = "e=ff"; |
334 | 334 |
335 ExpectIndex(64); | 335 // cookie: e=ff by index. |
336 ExpectIndex(63); | 336 ExpectIndex(62); |
| 337 ExpectIndexedLiteral("key1", "value1"); |
337 ExpectIndexedLiteral("key3", "value3"); | 338 ExpectIndexedLiteral("key3", "value3"); |
338 | 339 |
339 CompareWithExpectedEncoding(headers); | 340 CompareWithExpectedEncoding(headers); |
340 } | 341 } |
341 } | 342 } |
342 | 343 |
| 344 TEST_F(HpackEncoderTest, PseudoHeadersFirst) { |
| 345 map<string, string> headers; |
| 346 // A pseudo-header to be indexed. |
| 347 headers[":authority"] = "www.example.com"; |
| 348 // A pseudo-header that should not be indexed. |
| 349 headers[":path"] = "/spam/eggs.html"; |
| 350 // A regular header which precedes ":" alphabetically, should still be encoded |
| 351 // after pseudo-headers. |
| 352 headers["-foo"] = "bar"; |
| 353 headers["foo"] = "bar"; |
| 354 headers["cookie"] = "c=dd"; |
| 355 |
| 356 // Pseudo-headers are encoded in alphabetical order. |
| 357 ExpectIndexedLiteral(peer_.table()->GetByName(":authority"), |
| 358 "www.example.com"); |
| 359 ExpectNonIndexedLiteral(":path", "/spam/eggs.html"); |
| 360 // Regular headers in the header table are encoded first. |
| 361 ExpectIndex(IndexOf(cookie_a_)); |
| 362 // Regular headers not in the header table are encoded, in alphabetical order. |
| 363 ExpectIndexedLiteral("-foo", "bar"); |
| 364 ExpectIndexedLiteral("foo", "bar"); |
| 365 CompareWithExpectedEncoding(headers); |
| 366 } |
| 367 |
343 TEST_F(HpackEncoderTest, CookieToCrumbs) { | 368 TEST_F(HpackEncoderTest, CookieToCrumbs) { |
344 test::HpackEncoderPeer peer(NULL); | 369 test::HpackEncoderPeer peer(NULL); |
345 std::vector<StringPiece> out; | 370 std::vector<StringPiece> out; |
346 | 371 |
347 // A space after ';' is consumed. All other spaces remain. ';' at beginning | 372 // A space after ';' is consumed. All other spaces remain. ';' at beginning |
348 // and end of string produce empty crumbs. Duplicate crumbs are removed. | 373 // and end of string produce empty crumbs. Duplicate crumbs are removed. |
349 // See section 8.1.3.4 "Compressing the Cookie Header Field" in the HTTP/2 | 374 // See section 8.1.3.4 "Compressing the Cookie Header Field" in the HTTP/2 |
350 // specification at http://tools.ietf.org/html/draft-ietf-httpbis-http2-11 | 375 // specification at http://tools.ietf.org/html/draft-ietf-httpbis-http2-11 |
351 peer.CookieToCrumbs(" foo=1;bar=2 ; bar=3; bing=4; ", &out); | 376 peer.CookieToCrumbs(" foo=1;bar=2 ; bar=3; bing=4; ", &out); |
352 EXPECT_THAT(out, ElementsAre("", " bing=4", " foo=1", "bar=2 ", "bar=3")); | 377 EXPECT_THAT(out, ElementsAre("", " bing=4", " foo=1", "bar=2 ", "bar=3")); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 expect[static_cast<uint8>('\xff')] = 1; | 409 expect[static_cast<uint8>('\xff')] = 1; |
385 expect[static_cast<uint8>('b')] = 1; | 410 expect[static_cast<uint8>('b')] = 1; |
386 | 411 |
387 EXPECT_EQ(expect, counts); | 412 EXPECT_EQ(expect, counts); |
388 EXPECT_EQ(9u, total_counts); | 413 EXPECT_EQ(9u, total_counts); |
389 } | 414 } |
390 | 415 |
391 } // namespace | 416 } // namespace |
392 | 417 |
393 } // namespace net | 418 } // namespace net |
OLD | NEW |