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

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

Issue 822713002: Update from https://crrev.com/309415 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years 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
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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // header table). 57 // header table).
58 EmitIndexedLiteral(*it); 58 EmitIndexedLiteral(*it);
59 } else { 59 } else {
60 // Most common pseudo-header fields are represented in the static table, 60 // Most common pseudo-header fields are represented in the static table,
61 // while uncommon ones are small, so do not index them. 61 // while uncommon ones are small, so do not index them.
62 EmitNonIndexedLiteral(*it); 62 EmitNonIndexedLiteral(*it);
63 } 63 }
64 } 64 }
65 } 65 }
66 66
67 // Encode regular headers that are already in the header table first, 67 // Encode regular headers.
68 // save the rest into another vector. This way we avoid evicting an entry
69 // from the header table before it can be used.
70 Representations literal_headers;
71 for (Representations::const_iterator it = regular_headers.begin(); 68 for (Representations::const_iterator it = regular_headers.begin();
72 it != regular_headers.end(); ++it) { 69 it != regular_headers.end(); ++it) {
73 const HpackEntry* entry = 70 const HpackEntry* entry =
74 header_table_.GetByNameAndValue(it->first, it->second); 71 header_table_.GetByNameAndValue(it->first, it->second);
75 if (entry != NULL) { 72 if (entry != NULL) {
76 EmitIndex(entry); 73 EmitIndex(entry);
77 } else { 74 } else {
78 literal_headers.push_back(*it); 75 EmitIndexedLiteral(*it);
79 } 76 }
80 } 77 }
81 78
82 // Encode the remaining header fields, while inserting them in the header
83 // table.
84 for (Representations::const_iterator it = literal_headers.begin();
85 it != literal_headers.end(); ++it) {
86 EmitIndexedLiteral(*it);
87 }
88
89 output_stream_.TakeString(output); 79 output_stream_.TakeString(output);
90 return true; 80 return true;
91 } 81 }
92 82
93 bool HpackEncoder::EncodeHeaderSetWithoutCompression( 83 bool HpackEncoder::EncodeHeaderSetWithoutCompression(
94 const std::map<string, string>& header_set, 84 const std::map<string, string>& header_set,
95 string* output) { 85 string* output) {
96 86
97 allow_huffman_compression_ = false; 87 allow_huffman_compression_ = false;
98 for (std::map<string, string>::const_iterator it = header_set.begin(); 88 for (std::map<string, string>::const_iterator it = header_set.begin();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 size_t end = 0; 197 size_t end = 0;
208 while (end != StringPiece::npos) { 198 while (end != StringPiece::npos) {
209 end = header_field.second.find('\0', pos); 199 end = header_field.second.find('\0', pos);
210 out->push_back(make_pair(header_field.first, 200 out->push_back(make_pair(header_field.first,
211 header_field.second.substr(pos, end - pos))); 201 header_field.second.substr(pos, end - pos)));
212 pos = end + 1; 202 pos = end + 1;
213 } 203 }
214 } 204 }
215 205
216 } // namespace net 206 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698