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

Side by Side Diff: net/tools/quic/spdy_utils.cc

Issue 847813005: Updates quic_client_bin.cc to be more user friendly, and support more (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Refactoring_code_for_readability_83493327
Patch Set: Added DumpHeadersToString to dump response headers Created 5 years, 11 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
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/tools/quic/spdy_utils.h" 5 #include "net/tools/quic/spdy_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "net/spdy/spdy_frame_builder.h" 13 #include "net/spdy/spdy_frame_builder.h"
14 #include "net/spdy/spdy_framer.h" 14 #include "net/spdy/spdy_framer.h"
15 #include "net/spdy/spdy_protocol.h" 15 #include "net/spdy/spdy_protocol.h"
16 #include "net/tools/balsa/balsa_headers.h" 16 #include "net/tools/balsa/balsa_headers.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 using base::StringPiece; 19 using base::StringPiece;
20 using std::make_pair;
20 using std::pair; 21 using std::pair;
21 using std::string; 22 using std::string;
22 23
23 namespace net { 24 namespace net {
24 namespace tools { 25 namespace tools {
25 26
27 const char* const kV4Host = ":authority";
28
26 const char* const kV3Host = ":host"; 29 const char* const kV3Host = ":host";
27 const char* const kV3Path = ":path"; 30 const char* const kV3Path = ":path";
28 const char* const kV3Scheme = ":scheme"; 31 const char* const kV3Scheme = ":scheme";
29 const char* const kV3Status = ":status"; 32 const char* const kV3Status = ":status";
30 const char* const kV3Method = ":method"; 33 const char* const kV3Method = ":method";
31 const char* const kV3Version = ":version"; 34 const char* const kV3Version = ":version";
32 35
33 void PopulateSpdyHeaderBlock(const BalsaHeaders& headers, 36 void PopulateSpdyHeaderBlock(const BalsaHeaders& headers,
34 SpdyHeaderBlock* block, 37 SpdyHeaderBlock* block,
35 bool allow_empty_values) { 38 bool allow_empty_values) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 79
77 if (!headers.request_method().empty()) { 80 if (!headers.request_method().empty()) {
78 block->insert(make_pair(kV3Method, headers.request_method().as_string())); 81 block->insert(make_pair(kV3Method, headers.request_method().as_string()));
79 } 82 }
80 83
81 if (!headers.request_version().empty()) { 84 if (!headers.request_version().empty()) {
82 (*block)[kV3Version] = headers.request_version().as_string(); 85 (*block)[kV3Version] = headers.request_version().as_string();
83 } 86 }
84 } 87 }
85 88
89 void PopulateSpdy4RequestHeaderBlock(const BalsaHeaders& headers,
90 const string& scheme,
91 const string& host_and_port,
92 const string& path,
93 SpdyHeaderBlock* block) {
94 PopulateSpdyHeaderBlock(headers, block, true);
95 StringPiece host_header = headers.GetHeader("Host");
96 if (!host_header.empty()) {
97 DCHECK(host_and_port.empty() || host_header == host_and_port);
98 block->insert(make_pair(kV4Host, host_header.as_string()));
99 // PopulateSpdyHeaderBlock already added the "host" header,
100 // which is invalid for SPDY4.
101 block->erase("host");
102 } else {
103 block->insert(make_pair(kV4Host, host_and_port));
ramant (doing other things) 2015/01/13 01:35:47 rjshade: Is this right? Are we sending SPDY4 heade
rjshade 2015/01/13 15:22:36 See my other comment reply, but we aren't actually
104 }
105 block->insert(make_pair(kV3Path, path));
106 block->insert(make_pair(kV3Scheme, scheme));
107
108 if (!headers.request_method().empty()) {
109 block->insert(make_pair(kV3Method, headers.request_method().as_string()));
110 }
111 }
112
86 void PopulateSpdyResponseHeaderBlock(const BalsaHeaders& headers, 113 void PopulateSpdyResponseHeaderBlock(const BalsaHeaders& headers,
87 SpdyHeaderBlock* block) { 114 SpdyHeaderBlock* block) {
88 string status = headers.response_code().as_string(); 115 string status = headers.response_code().as_string();
89 status.append(" "); 116 status.append(" ");
90 status.append(headers.response_reason_phrase().as_string()); 117 status.append(headers.response_reason_phrase().as_string());
91 (*block)[kV3Status] = status; 118 (*block)[kV3Status] = status;
92 (*block)[kV3Version] = 119 (*block)[kV3Version] =
93 headers.response_version().as_string(); 120 headers.response_version().as_string();
94 121
95 // Empty header values are only allowed because this is spdy3. 122 // Empty header values are only allowed because this is spdy3.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 SpdyHeaderBlock block; 154 SpdyHeaderBlock block;
128 PopulateSpdy3RequestHeaderBlock( 155 PopulateSpdy3RequestHeaderBlock(
129 request_headers, scheme, host_and_port, path, &block); 156 request_headers, scheme, host_and_port, path, &block);
130 if (block.find("host") != block.end()) { 157 if (block.find("host") != block.end()) {
131 block.erase(block.find("host")); 158 block.erase(block.find("host"));
132 } 159 }
133 return block; 160 return block;
134 } 161 }
135 162
136 // static 163 // static
164 SpdyHeaderBlock SpdyUtils::RequestHeadersToSpdy4Headers(
165 const BalsaHeaders& request_headers) {
166 string scheme;
167 string host_and_port;
168 string path;
169
170 string url = request_headers.request_uri().as_string();
171 if (url.empty() || url[0] == '/') {
172 path = url;
173 } else {
174 GURL request_uri(url);
175 if (request_headers.request_method() == "CONNECT") {
176 path = url;
177 } else {
178 path = request_uri.path();
179 if (!request_uri.query().empty()) {
180 path = path + "?" + request_uri.query();
181 }
182 host_and_port = request_uri.host();
183 scheme = request_uri.scheme();
184 }
185 }
186
187 DCHECK(!scheme.empty());
188 DCHECK(!host_and_port.empty());
189 DCHECK(!path.empty());
190
191 SpdyHeaderBlock block;
192 PopulateSpdy4RequestHeaderBlock(request_headers, scheme, host_and_port, path,
193 &block);
194 if (block.find("host") != block.end()) {
195 block.erase(block.find("host"));
196 }
197 return block;
198 }
199
200 // static
137 string SpdyUtils::SerializeRequestHeaders(const BalsaHeaders& request_headers) { 201 string SpdyUtils::SerializeRequestHeaders(const BalsaHeaders& request_headers) {
138 SpdyHeaderBlock block = RequestHeadersToSpdyHeaders(request_headers); 202 SpdyHeaderBlock block = RequestHeadersToSpdyHeaders(request_headers);
139 return SerializeUncompressedHeaders(block); 203 return SerializeUncompressedHeaders(block);
140 } 204 }
141 205
142 // static 206 // static
143 SpdyHeaderBlock SpdyUtils::ResponseHeadersToSpdyHeaders( 207 SpdyHeaderBlock SpdyUtils::ResponseHeadersToSpdyHeaders(
144 const BalsaHeaders& response_headers) { 208 const BalsaHeaders& response_headers) {
145 SpdyHeaderBlock block; 209 SpdyHeaderBlock block;
146 PopulateSpdyResponseHeaderBlock(response_headers, &block); 210 PopulateSpdyResponseHeaderBlock(response_headers, &block);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) { 321 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) {
258 if (!IsSpecialSpdyHeader(it, request_headers)) { 322 if (!IsSpecialSpdyHeader(it, request_headers)) {
259 request_headers->AppendHeader(it->first, it->second); 323 request_headers->AppendHeader(it->first, it->second);
260 } 324 }
261 } 325 }
262 return true; 326 return true;
263 } 327 }
264 328
265 } // namespace tools 329 } // namespace tools
266 } // namespace net 330 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698