| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/spdy/hpack_header_table.h" | 10 #include "net/spdy/hpack_header_table.h" |
| 11 #include "net/spdy/hpack_huffman_table.h" | 11 #include "net/spdy/hpack_huffman_table.h" |
| 12 #include "net/spdy/hpack_output_stream.h" | 12 #include "net/spdy/hpack_output_stream.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 using base::StringPiece; | 16 using base::StringPiece; |
| 17 using std::string; | 17 using std::string; |
| 18 | 18 |
| 19 HpackEncoder::HpackEncoder(const HpackHuffmanTable& table) | 19 HpackEncoder::HpackEncoder(const HpackHuffmanTable& table) |
| 20 : output_stream_(), | 20 : output_stream_(), |
| 21 allow_huffman_compression_(true), | 21 allow_huffman_compression_(true), |
| 22 huffman_table_(table), | 22 huffman_table_(table), |
| 23 char_counts_(NULL), | 23 char_counts_(NULL), |
| 24 total_char_counts_(NULL) {} | 24 total_char_counts_(NULL) {} |
| 25 | 25 |
| 26 HpackEncoder::~HpackEncoder() {} | 26 HpackEncoder::~HpackEncoder() {} |
| 27 | 27 |
| 28 bool HpackEncoder::EncodeHeaderSet(const std::map<string, string>& header_set, | 28 bool HpackEncoder::EncodeHeaderSet(const SpdyHeaderBlock& header_set, |
| 29 string* output) { | 29 string* output) { |
| 30 // Separate header set into pseudo-headers and regular headers. | 30 // Separate header set into pseudo-headers and regular headers. |
| 31 Representations pseudo_headers; | 31 Representations pseudo_headers; |
| 32 Representations regular_headers; | 32 Representations regular_headers; |
| 33 for (const auto& header : header_set) { | 33 for (const auto& header : header_set) { |
| 34 if (header.first == "cookie") { | 34 if (header.first == "cookie") { |
| 35 // Note that there can only be one "cookie" header, because header_set is | 35 // Note that there can only be one "cookie" header, because header_set is |
| 36 // a map. | 36 // a map. |
| 37 CookieToCrumbs(header, ®ular_headers); | 37 CookieToCrumbs(header, ®ular_headers); |
| 38 } else if (header.first[0] == kPseudoHeaderPrefix) { | 38 } else if (header.first[0] == kPseudoHeaderPrefix) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } else { | 71 } else { |
| 72 EmitIndexedLiteral(header); | 72 EmitIndexedLiteral(header); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 output_stream_.TakeString(output); | 76 output_stream_.TakeString(output); |
| 77 return true; | 77 return true; |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool HpackEncoder::EncodeHeaderSetWithoutCompression( | 80 bool HpackEncoder::EncodeHeaderSetWithoutCompression( |
| 81 const std::map<string, string>& header_set, | 81 const SpdyHeaderBlock& header_set, |
| 82 string* output) { | 82 string* output) { |
| 83 | |
| 84 allow_huffman_compression_ = false; | 83 allow_huffman_compression_ = false; |
| 85 for (const auto& header : header_set) { | 84 for (const auto& header : header_set) { |
| 86 // Note that cookies are not crumbled in this case. | 85 // Note that cookies are not crumbled in this case. |
| 87 EmitNonIndexedLiteral(header); | 86 EmitNonIndexedLiteral(header); |
| 88 } | 87 } |
| 89 allow_huffman_compression_ = true; | 88 allow_huffman_compression_ = true; |
| 90 output_stream_.TakeString(output); | 89 output_stream_.TakeString(output); |
| 91 return true; | 90 return true; |
| 92 } | 91 } |
| 93 | 92 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 size_t end = 0; | 189 size_t end = 0; |
| 191 while (end != StringPiece::npos) { | 190 while (end != StringPiece::npos) { |
| 192 end = header_field.second.find('\0', pos); | 191 end = header_field.second.find('\0', pos); |
| 193 out->push_back(std::make_pair(header_field.first, | 192 out->push_back(std::make_pair(header_field.first, |
| 194 header_field.second.substr(pos, end - pos))); | 193 header_field.second.substr(pos, end - pos))); |
| 195 pos = end + 1; | 194 pos = end + 1; |
| 196 } | 195 } |
| 197 } | 196 } |
| 198 | 197 |
| 199 } // namespace net | 198 } // namespace net |
| OLD | NEW |