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" |
(...skipping 19 matching lines...) Expand all Loading... |
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 (std::map<string, string>::const_iterator it = header_set.begin(); | 33 for (std::map<string, string>::const_iterator it = header_set.begin(); |
34 it != header_set.end(); ++it) { | 34 it != header_set.end(); ++it) { |
35 if (it->first == "cookie") { | 35 if (it->first == "cookie") { |
36 // Note that there can only be one "cookie" header, because header_set is | 36 // Note that there can only be one "cookie" header, because header_set is |
37 // a map. | 37 // a map. |
38 CookieToCrumbs(*it, ®ular_headers); | 38 CookieToCrumbs(*it, ®ular_headers); |
39 } else if (it->first[0] == kPseudoHeaderPrefix) { | 39 } else if (it->first[0] == kPseudoHeaderPrefix) { |
40 pseudo_headers.push_back(make_pair( | 40 DecomposeRepresentation(*it, &pseudo_headers); |
41 StringPiece(it->first), StringPiece(it->second))); | |
42 } else { | 41 } else { |
43 regular_headers.push_back(make_pair( | 42 DecomposeRepresentation(*it, ®ular_headers); |
44 StringPiece(it->first), StringPiece(it->second))); | |
45 } | 43 } |
46 } | 44 } |
47 | 45 |
48 // Encode pseudo-headers. | 46 // Encode pseudo-headers. |
49 for (Representations::const_iterator it = pseudo_headers.begin(); | 47 for (Representations::const_iterator it = pseudo_headers.begin(); |
50 it != pseudo_headers.end(); ++it) { | 48 it != pseudo_headers.end(); ++it) { |
51 HpackEntry* entry = header_table_.GetByNameAndValue(it->first, it->second); | 49 HpackEntry* entry = header_table_.GetByNameAndValue(it->first, it->second); |
52 if (entry != NULL) { | 50 if (entry != NULL) { |
53 EmitIndex(entry); | 51 EmitIndex(entry); |
54 } else { | 52 } else { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 if (pos != cookie.second.size() && cookie.second[pos] == ' ') { | 191 if (pos != cookie.second.size() && cookie.second[pos] == ' ') { |
194 pos++; | 192 pos++; |
195 } | 193 } |
196 } | 194 } |
197 // Sort crumbs and remove duplicates. | 195 // Sort crumbs and remove duplicates. |
198 std::sort(out->begin() + prior_size, out->end()); | 196 std::sort(out->begin() + prior_size, out->end()); |
199 out->erase(std::unique(out->begin() + prior_size, out->end()), | 197 out->erase(std::unique(out->begin() + prior_size, out->end()), |
200 out->end()); | 198 out->end()); |
201 } | 199 } |
202 | 200 |
| 201 // static |
| 202 void HpackEncoder::DecomposeRepresentation(const Representation& header_field, |
| 203 Representations* out) { |
| 204 size_t pos = 0; |
| 205 size_t end = 0; |
| 206 while (end != StringPiece::npos) { |
| 207 end = header_field.second.find('\0', pos); |
| 208 out->push_back(make_pair(header_field.first, |
| 209 header_field.second.substr(pos, end - pos))); |
| 210 pos = end + 1; |
| 211 } |
| 212 } |
| 213 |
203 } // namespace net | 214 } // namespace net |
OLD | NEW |