OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spdy_http_utils.h" | 5 #include "net/spdy/spdy_http_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
13 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
14 #include "net/base/url_util.h" | 15 #include "net/base/url_util.h" |
15 #include "net/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
16 #include "net/http/http_request_info.h" | 17 #include "net/http/http_request_info.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "net/http/http_response_info.h" | 19 #include "net/http/http_response_info.h" |
19 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 | 186 |
186 NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( | 187 NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( |
187 SpdyPriority priority, | 188 SpdyPriority priority, |
188 SpdyMajorVersion protocol_version) { | 189 SpdyMajorVersion protocol_version) { |
189 // Handle invalid values gracefully. | 190 // Handle invalid values gracefully. |
190 // Note that SpdyPriority is not an enum, hence the magic constants. | 191 // Note that SpdyPriority is not an enum, hence the magic constants. |
191 return (priority >= 5) ? | 192 return (priority >= 5) ? |
192 IDLE : static_cast<RequestPriority>(4 - priority); | 193 IDLE : static_cast<RequestPriority>(4 - priority); |
193 } | 194 } |
194 | 195 |
196 NET_EXPORT_PRIVATE void ConvertHeaderBlockToHttpRequestHeaders( | |
197 const SpdyHeaderBlock& spdy_headers, | |
198 HttpRequestHeaders* http_headers) { | |
199 for (auto it : spdy_headers) { | |
Ryan Hamilton
2016/02/29 17:49:40
const auto& ?
Buck
2016/02/29 19:03:02
Done.
| |
200 base::StringPiece key = it.first; | |
201 if (key[0] == ':') { | |
202 key.remove_prefix(1); | |
203 } | |
204 std::vector<base::StringPiece> values = base::SplitStringPiece( | |
205 it.second, "\0", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
206 for (auto value : values) { | |
Ryan Hamilton
2016/02/29 17:49:40
const auto& ?
Buck
2016/02/29 19:03:02
Done.
| |
207 http_headers->SetHeader(key, value); | |
208 } | |
209 } | |
210 } | |
211 | |
195 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, | 212 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, |
196 SpdyMajorVersion protocol_version) { | 213 SpdyMajorVersion protocol_version) { |
197 SpdyHeaderBlock::const_iterator it = headers.find(":scheme"); | 214 SpdyHeaderBlock::const_iterator it = headers.find(":scheme"); |
198 if (it == headers.end()) | 215 if (it == headers.end()) |
199 return GURL(); | 216 return GURL(); |
200 std::string url = it->second.as_string(); | 217 std::string url = it->second.as_string(); |
201 url.append("://"); | 218 url.append("://"); |
202 | 219 |
203 it = headers.find(protocol_version >= HTTP2 ? ":authority" : ":host"); | 220 it = headers.find(protocol_version >= HTTP2 ? ":authority" : ":host"); |
204 if (it == headers.end()) | 221 if (it == headers.end()) |
205 return GURL(); | 222 return GURL(); |
206 url.append(it->second.as_string()); | 223 url.append(it->second.as_string()); |
207 | 224 |
208 it = headers.find(":path"); | 225 it = headers.find(":path"); |
209 if (it == headers.end()) | 226 if (it == headers.end()) |
210 return GURL(); | 227 return GURL(); |
211 url.append(it->second.as_string()); | 228 url.append(it->second.as_string()); |
212 return GURL(url); | 229 return GURL(url); |
213 } | 230 } |
214 | 231 |
215 } // namespace net | 232 } // namespace net |
OLD | NEW |