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_constants.h" | 5 #include "net/spdy/hpack_constants.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
10 #include "net/spdy/hpack_huffman_table.h" | 12 #include "net/spdy/hpack_huffman_table.h" |
| 13 #include "net/spdy/hpack_static_table.h" |
11 | 14 |
12 namespace net { | 15 namespace net { |
13 | 16 |
14 namespace { | 17 namespace { |
15 | 18 |
16 | 19 |
17 // SharedHpackHuffmanTable is a Singleton wrapping a HpackHuffmanTable | 20 // SharedHpackHuffmanTable is a Singleton wrapping a HpackHuffmanTable |
18 // instance initialized with |kHpackHuffmanCode|. | 21 // instance initialized with |kHpackHuffmanCode|. |
19 struct SharedHpackHuffmanTable { | 22 struct SharedHpackHuffmanTable { |
20 public: | 23 public: |
21 SharedHpackHuffmanTable() { | 24 SharedHpackHuffmanTable() { |
22 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); | 25 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); |
23 scoped_ptr<HpackHuffmanTable> mutable_table(new HpackHuffmanTable()); | 26 scoped_ptr<HpackHuffmanTable> mutable_table(new HpackHuffmanTable()); |
24 CHECK(mutable_table->Initialize(&code[0], code.size())); | 27 CHECK(mutable_table->Initialize(&code[0], code.size())); |
25 CHECK(mutable_table->IsInitialized()); | 28 CHECK(mutable_table->IsInitialized()); |
26 table.reset(mutable_table.release()); | 29 table.reset(mutable_table.release()); |
27 } | 30 } |
28 | 31 |
29 static SharedHpackHuffmanTable* GetInstance() { | 32 static SharedHpackHuffmanTable* GetInstance() { |
30 return Singleton<SharedHpackHuffmanTable>::get(); | 33 return Singleton<SharedHpackHuffmanTable>::get(); |
31 } | 34 } |
32 | 35 |
33 scoped_ptr<const HpackHuffmanTable> table; | 36 scoped_ptr<const HpackHuffmanTable> table; |
34 }; | 37 }; |
35 | 38 |
| 39 // SharedHpackStaticTable is a Singleton wrapping a HpackStaticTable |
| 40 // instance initialized with |kHpackStaticTable|. |
| 41 struct SharedHpackStaticTable { |
| 42 public: |
| 43 SharedHpackStaticTable() { |
| 44 std::vector<HpackStaticEntry> static_table = HpackStaticTableVector(); |
| 45 scoped_ptr<HpackStaticTable> mutable_table(new HpackStaticTable()); |
| 46 mutable_table->Initialize(&static_table[0], static_table.size()); |
| 47 CHECK(mutable_table->IsInitialized()); |
| 48 table.reset(mutable_table.release()); |
| 49 } |
| 50 |
| 51 static SharedHpackStaticTable* GetInstance() { |
| 52 return Singleton<SharedHpackStaticTable>::get(); |
| 53 } |
| 54 |
| 55 scoped_ptr<const HpackStaticTable> table; |
| 56 }; |
| 57 |
36 } // namespace | 58 } // namespace |
37 | 59 |
38 // Produced by applying the python program [1] with tables | 60 // Produced by applying the python program [1] with tables |
39 // provided by [2] (inserted into the source of the python program) | 61 // provided by [2] (inserted into the source of the python program) |
40 // and copy-paste them into this file. | 62 // and copy-paste them into this file. |
41 // | 63 // |
42 // [1] net/tools/build_hpack_constants.py | 64 // [1] net/tools/build_hpack_constants.py |
43 // [2] http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 | 65 // [2] http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
44 | 66 |
45 // HpackHuffmanSymbol entries are initialized as {code, length, id}. | 67 // HpackHuffmanSymbol entries are initialized as {code, length, id}. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 {0xfffffde0ul, 27, 253}, // 11111111|11111111|11111101|111 | 324 {0xfffffde0ul, 27, 253}, // 11111111|11111111|11111101|111 |
303 {0xfffffe00ul, 27, 254}, // 11111111|11111111|11111110|000 | 325 {0xfffffe00ul, 27, 254}, // 11111111|11111111|11111110|000 |
304 {0xfffffb80ul, 26, 255}, // 11111111|11111111|11111011|10 | 326 {0xfffffb80ul, 26, 255}, // 11111111|11111111|11111011|10 |
305 {0xfffffffcul, 30, 256}, // EOS 11111111|11111111|11111111|111111 | 327 {0xfffffffcul, 30, 256}, // EOS 11111111|11111111|11111111|111111 |
306 }; | 328 }; |
307 return std::vector<HpackHuffmanSymbol>( | 329 return std::vector<HpackHuffmanSymbol>( |
308 kHpackHuffmanCode, | 330 kHpackHuffmanCode, |
309 kHpackHuffmanCode + arraysize(kHpackHuffmanCode)); | 331 kHpackHuffmanCode + arraysize(kHpackHuffmanCode)); |
310 } | 332 } |
311 | 333 |
| 334 // The "constructor" for a HpackStaticEntry that computes the lengths at |
| 335 // compile time. |
| 336 #define STATIC_ENTRY(name, value) \ |
| 337 { name, arraysize(name) - 1, value, arraysize(value) - 1 } |
| 338 |
| 339 std::vector<HpackStaticEntry> HpackStaticTableVector() { |
| 340 static const HpackStaticEntry kHpackStaticTable[] = { |
| 341 STATIC_ENTRY(":authority", ""), // 1 |
| 342 STATIC_ENTRY(":method", "GET"), // 2 |
| 343 STATIC_ENTRY(":method", "POST"), // 3 |
| 344 STATIC_ENTRY(":path", "/"), // 4 |
| 345 STATIC_ENTRY(":path", "/index.html"), // 5 |
| 346 STATIC_ENTRY(":scheme", "http"), // 6 |
| 347 STATIC_ENTRY(":scheme", "https"), // 7 |
| 348 STATIC_ENTRY(":status", "200"), // 8 |
| 349 STATIC_ENTRY(":status", "204"), // 9 |
| 350 STATIC_ENTRY(":status", "206"), // 10 |
| 351 STATIC_ENTRY(":status", "304"), // 11 |
| 352 STATIC_ENTRY(":status", "400"), // 12 |
| 353 STATIC_ENTRY(":status", "404"), // 13 |
| 354 STATIC_ENTRY(":status", "500"), // 14 |
| 355 STATIC_ENTRY("accept-charset", ""), // 15 |
| 356 STATIC_ENTRY("accept-encoding", "gzip, deflate"), // 16 |
| 357 STATIC_ENTRY("accept-language", ""), // 17 |
| 358 STATIC_ENTRY("accept-ranges", ""), // 18 |
| 359 STATIC_ENTRY("accept", ""), // 19 |
| 360 STATIC_ENTRY("access-control-allow-origin", ""), // 20 |
| 361 STATIC_ENTRY("age", ""), // 21 |
| 362 STATIC_ENTRY("allow", ""), // 22 |
| 363 STATIC_ENTRY("authorization", ""), // 23 |
| 364 STATIC_ENTRY("cache-control", ""), // 24 |
| 365 STATIC_ENTRY("content-disposition", ""), // 25 |
| 366 STATIC_ENTRY("content-encoding", ""), // 26 |
| 367 STATIC_ENTRY("content-language", ""), // 27 |
| 368 STATIC_ENTRY("content-length", ""), // 28 |
| 369 STATIC_ENTRY("content-location", ""), // 29 |
| 370 STATIC_ENTRY("content-range", ""), // 30 |
| 371 STATIC_ENTRY("content-type", ""), // 31 |
| 372 STATIC_ENTRY("cookie", ""), // 32 |
| 373 STATIC_ENTRY("date", ""), // 33 |
| 374 STATIC_ENTRY("etag", ""), // 34 |
| 375 STATIC_ENTRY("expect", ""), // 35 |
| 376 STATIC_ENTRY("expires", ""), // 36 |
| 377 STATIC_ENTRY("from", ""), // 37 |
| 378 STATIC_ENTRY("host", ""), // 38 |
| 379 STATIC_ENTRY("if-match", ""), // 39 |
| 380 STATIC_ENTRY("if-modified-since", ""), // 40 |
| 381 STATIC_ENTRY("if-none-match", ""), // 41 |
| 382 STATIC_ENTRY("if-range", ""), // 42 |
| 383 STATIC_ENTRY("if-unmodified-since", ""), // 43 |
| 384 STATIC_ENTRY("last-modified", ""), // 44 |
| 385 STATIC_ENTRY("link", ""), // 45 |
| 386 STATIC_ENTRY("location", ""), // 46 |
| 387 STATIC_ENTRY("max-forwards", ""), // 47 |
| 388 STATIC_ENTRY("proxy-authenticate", ""), // 48 |
| 389 STATIC_ENTRY("proxy-authorization", ""), // 49 |
| 390 STATIC_ENTRY("range", ""), // 50 |
| 391 STATIC_ENTRY("referer", ""), // 51 |
| 392 STATIC_ENTRY("refresh", ""), // 52 |
| 393 STATIC_ENTRY("retry-after", ""), // 53 |
| 394 STATIC_ENTRY("server", ""), // 54 |
| 395 STATIC_ENTRY("set-cookie", ""), // 55 |
| 396 STATIC_ENTRY("strict-transport-security", ""), // 56 |
| 397 STATIC_ENTRY("transfer-encoding", ""), // 57 |
| 398 STATIC_ENTRY("user-agent", ""), // 58 |
| 399 STATIC_ENTRY("vary", ""), // 59 |
| 400 STATIC_ENTRY("via", ""), // 60 |
| 401 STATIC_ENTRY("www-authenticate", ""), // 61 |
| 402 }; |
| 403 return std::vector<HpackStaticEntry>( |
| 404 kHpackStaticTable, |
| 405 kHpackStaticTable + arraysize(kHpackStaticTable)); |
| 406 } |
| 407 |
| 408 #undef STATIC_ENTRY |
| 409 |
312 const HpackHuffmanTable& ObtainHpackHuffmanTable() { | 410 const HpackHuffmanTable& ObtainHpackHuffmanTable() { |
313 return *SharedHpackHuffmanTable::GetInstance()->table; | 411 return *SharedHpackHuffmanTable::GetInstance()->table; |
314 } | 412 } |
315 | 413 |
| 414 const HpackStaticTable& ObtainHpackStaticTable() { |
| 415 return *SharedHpackStaticTable::GetInstance()->table; |
| 416 } |
| 417 |
316 } // namespace net | 418 } // namespace net |
OLD | NEW |