Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: net/spdy/hpack_encoder.cc

Issue 1263803002: Replace SpdyNameValueBlock typedef with SpdyHeaderBlock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/hpack_encoder.h ('k') | net/spdy/hpack_encoder_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, &regular_headers); 37 CookieToCrumbs(header, &regular_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
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
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
OLDNEW
« no previous file with comments | « net/spdy/hpack_encoder.h ('k') | net/spdy/hpack_encoder_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698