| 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_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 std::string value = it->second.as_string(); | 77 std::string value = it->second.as_string(); |
| 78 size_t start = 0; | 78 size_t start = 0; |
| 79 size_t end = 0; | 79 size_t end = 0; |
| 80 do { | 80 do { |
| 81 end = value.find('\0', start); | 81 end = value.find('\0', start); |
| 82 std::string tval; | 82 std::string tval; |
| 83 if (end != value.npos) | 83 if (end != value.npos) |
| 84 tval = value.substr(start, (end - start)); | 84 tval = value.substr(start, (end - start)); |
| 85 else | 85 else |
| 86 tval = value.substr(start); | 86 tval = value.substr(start); |
| 87 if (protocol_version >= 3 && it->first[0] == ':') | 87 if (it->first[0] == ':') |
| 88 raw_headers.append(it->first.as_string().substr(1)); | 88 raw_headers.append(it->first.as_string().substr(1)); |
| 89 else | 89 else |
| 90 raw_headers.append(it->first.as_string()); | 90 raw_headers.append(it->first.as_string()); |
| 91 raw_headers.push_back(':'); | 91 raw_headers.push_back(':'); |
| 92 raw_headers.append(tval); | 92 raw_headers.append(tval); |
| 93 raw_headers.push_back('\0'); | 93 raw_headers.push_back('\0'); |
| 94 start = end + 1; | 94 start = end + 1; |
| 95 } while (end != value.npos); | 95 } while (end != value.npos); |
| 96 } | 96 } |
| 97 | 97 |
| 98 response->headers = new HttpResponseHeaders(raw_headers); | 98 response->headers = new HttpResponseHeaders(raw_headers); |
| 99 response->was_fetched_via_spdy = true; | 99 response->was_fetched_via_spdy = true; |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, | 103 void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, |
| 104 const HttpRequestHeaders& request_headers, | 104 const HttpRequestHeaders& request_headers, |
| 105 SpdyMajorVersion protocol_version, | 105 SpdyMajorVersion protocol_version, |
| 106 bool direct, | 106 bool direct, |
| 107 SpdyHeaderBlock* headers) { | 107 SpdyHeaderBlock* headers) { |
| 108 static const char kHttpProtocolVersion[] = "HTTP/1.1"; | 108 static const char kHttpProtocolVersion[] = "HTTP/1.1"; |
| 109 switch (protocol_version) { | 109 switch (protocol_version) { |
| 110 case SPDY2: | |
| 111 // TODO(bnc): Remove this code now that SPDY/2 is deprecated. | |
| 112 (*headers)["version"] = kHttpProtocolVersion; | |
| 113 (*headers)["method"] = info.method; | |
| 114 (*headers)["host"] = GetHostAndOptionalPort(info.url); | |
| 115 if (info.method == "CONNECT") { | |
| 116 (*headers)["url"] = GetHostAndPort(info.url); | |
| 117 } else { | |
| 118 (*headers)["scheme"] = info.url.scheme(); | |
| 119 (*headers)["url"] = direct ? info.url.PathForRequest() | |
| 120 : HttpUtil::SpecForRequest(info.url); | |
| 121 } | |
| 122 break; | |
| 123 case SPDY3: | 110 case SPDY3: |
| 124 (*headers)[":version"] = kHttpProtocolVersion; | 111 (*headers)[":version"] = kHttpProtocolVersion; |
| 125 (*headers)[":method"] = info.method; | 112 (*headers)[":method"] = info.method; |
| 126 (*headers)[":host"] = GetHostAndOptionalPort(info.url); | 113 (*headers)[":host"] = GetHostAndOptionalPort(info.url); |
| 127 if (info.method == "CONNECT") { | 114 if (info.method == "CONNECT") { |
| 128 (*headers)[":path"] = GetHostAndPort(info.url); | 115 (*headers)[":path"] = GetHostAndPort(info.url); |
| 129 } else { | 116 } else { |
| 130 (*headers)[":scheme"] = info.url.scheme(); | 117 (*headers)[":scheme"] = info.url.scheme(); |
| 131 (*headers)[":path"] = info.url.PathForRequest(); | 118 (*headers)[":path"] = info.url.PathForRequest(); |
| 132 } | 119 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 url.append(it->second.as_string()); | 208 url.append(it->second.as_string()); |
| 222 | 209 |
| 223 it = headers.find(":path"); | 210 it = headers.find(":path"); |
| 224 if (it == headers.end()) | 211 if (it == headers.end()) |
| 225 return GURL(); | 212 return GURL(); |
| 226 url.append(it->second.as_string()); | 213 url.append(it->second.as_string()); |
| 227 return GURL(url); | 214 return GURL(url); |
| 228 } | 215 } |
| 229 | 216 |
| 230 } // namespace net | 217 } // namespace net |
| OLD | NEW |