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

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

Issue 9958023: Properly handle spdy3 responses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_http_utils.h ('k') | net/spdy/spdy_network_transaction_spdy3_unittest.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 (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/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "net/base/escape.h"
12 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
13 #include "net/base/net_util.h" 14 #include "net/base/net_util.h"
14 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
15 #include "net/http/http_request_info.h" 16 #include "net/http/http_request_info.h"
16 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
17 #include "net/http/http_response_info.h" 18 #include "net/http/http_response_info.h"
18 #include "net/http/http_util.h" 19 #include "net/http/http_util.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 bool SpdyHeadersToHttpResponse(const SpdyHeaderBlock& headers, 23 bool SpdyHeadersToHttpResponse(const SpdyHeaderBlock& headers,
24 int protocol_version,
23 HttpResponseInfo* response) { 25 HttpResponseInfo* response) {
26 std::string status_key = (protocol_version >= 3) ? ":status" : "status";
27 std::string version_key = (protocol_version >= 3) ? ":version" : "version";
24 std::string version; 28 std::string version;
25 std::string status; 29 std::string status;
26 30
27 // The "status" and "version" headers are required. 31 // The "status" and "version" headers are required.
28 SpdyHeaderBlock::const_iterator it; 32 SpdyHeaderBlock::const_iterator it;
29 it = headers.find("status"); 33 it = headers.find(status_key);
30 if (it == headers.end()) 34 if (it == headers.end())
31 return false; 35 return false;
32 status = it->second; 36 status = it->second;
33 37
34 // Grab the version. If not provided by the server, 38 it = headers.find(version_key);
35 it = headers.find("version");
36 if (it == headers.end()) 39 if (it == headers.end())
37 return false; 40 return false;
38 version = it->second; 41 version = it->second;
39 42
40 response->response_time = base::Time::Now(); 43 response->response_time = base::Time::Now();
41 44
42 std::string raw_headers(version); 45 std::string raw_headers(version);
43 raw_headers.push_back(' '); 46 raw_headers.push_back(' ');
44 raw_headers.append(status); 47 raw_headers.append(status);
45 raw_headers.push_back('\0'); 48 raw_headers.push_back('\0');
46 for (it = headers.begin(); it != headers.end(); ++it) { 49 for (it = headers.begin(); it != headers.end(); ++it) {
47 // For each value, if the server sends a NUL-separated 50 // For each value, if the server sends a NUL-separated
48 // list of values, we separate that back out into 51 // list of values, we separate that back out into
49 // individual headers for each value in the list. 52 // individual headers for each value in the list.
50 // e.g. 53 // e.g.
51 // Set-Cookie "foo\0bar" 54 // Set-Cookie "foo\0bar"
52 // becomes 55 // becomes
53 // Set-Cookie: foo\0 56 // Set-Cookie: foo\0
54 // Set-Cookie: bar\0 57 // Set-Cookie: bar\0
55 std::string value = it->second; 58 std::string value = it->second;
56 size_t start = 0; 59 size_t start = 0;
57 size_t end = 0; 60 size_t end = 0;
58 do { 61 do {
59 end = value.find('\0', start); 62 end = value.find('\0', start);
60 std::string tval; 63 std::string tval;
61 if (end != value.npos) 64 if (end != value.npos)
62 tval = value.substr(start, (end - start)); 65 tval = value.substr(start, (end - start));
63 else 66 else
64 tval = value.substr(start); 67 tval = value.substr(start);
65 raw_headers.append(it->first); 68 if (protocol_version >= 3 && it->first[0] == ':')
69 raw_headers.append(it->first.substr(1));
70 else
71 raw_headers.append(it->first);
66 raw_headers.push_back(':'); 72 raw_headers.push_back(':');
67 raw_headers.append(tval); 73 raw_headers.append(tval);
68 raw_headers.push_back('\0'); 74 raw_headers.push_back('\0');
69 start = end + 1; 75 start = end + 1;
70 } while (end != value.npos); 76 } while (end != value.npos);
71 } 77 }
72 78
73 response->headers = new HttpResponseHeaders(raw_headers); 79 response->headers = new HttpResponseHeaders(raw_headers);
74 response->was_fetched_via_spdy = true; 80 response->was_fetched_via_spdy = true;
75 return true; 81 return true;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 switch (priority) { 132 switch (priority) {
127 case LOWEST: 133 case LOWEST:
128 return SPDY_PRIORITY_LOWEST - 1; 134 return SPDY_PRIORITY_LOWEST - 1;
129 case IDLE: 135 case IDLE:
130 return SPDY_PRIORITY_LOWEST; 136 return SPDY_PRIORITY_LOWEST;
131 default: 137 default:
132 return priority; 138 return priority;
133 } 139 }
134 } 140 }
135 141
142 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers,
143 int protocol_version,
144 bool pushed) {
145 // SPDY 2 server push urls are specified in a single "url" header.
146 if (pushed && protocol_version == 2) {
147 std::string url;
148 SpdyHeaderBlock::const_iterator it;
149 it = headers.find("url");
150 if (it != headers.end())
151 url = it->second;
152 return GURL(url);
153 }
154
155 const char* scheme_header = protocol_version >= 3 ? ":scheme" : "scheme";
156 const char* host_header = protocol_version >= 3 ? ":host" : "host";
157 const char* path_header = protocol_version >= 3 ? ":path" : "url";
158
159 std::string scheme;
160 std::string host_port;
161 std::string path;
162 SpdyHeaderBlock::const_iterator it;
163 it = headers.find(scheme_header);
164 if (it != headers.end())
165 scheme = it->second;
166 it = headers.find(host_header);
167 if (it != headers.end())
168 host_port = it->second;
169 it = headers.find(path_header);
170 if (it != headers.end())
171 path = it->second;
172
173 std::string url = (scheme.empty() || host_port.empty() || path.empty())
174 ? "" : scheme + "://" + host_port + path;
175 return GURL(url);
176 }
177
136 } // namespace net 178 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_http_utils.h ('k') | net/spdy/spdy_network_transaction_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698