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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/tools/quic/spdy_utils.cc
diff --git a/net/tools/quic/spdy_utils.cc b/net/tools/quic/spdy_utils.cc
index 8fc5991d7441c93ef5f8b479af47d5f46bfbb64d..c2b61740d9f56238e35dab5a3e220250506a386f 100644
--- a/net/tools/quic/spdy_utils.cc
+++ b/net/tools/quic/spdy_utils.cc
@@ -17,12 +17,15 @@
#include "url/gurl.h"
using base::StringPiece;
+using std::make_pair;
using std::pair;
using std::string;
namespace net {
namespace tools {
+const char* const kV4Host = ":authority";
+
const char* const kV3Host = ":host";
const char* const kV3Path = ":path";
const char* const kV3Scheme = ":scheme";
@@ -83,6 +86,30 @@ void PopulateSpdy3RequestHeaderBlock(const BalsaHeaders& headers,
}
}
+void PopulateSpdy4RequestHeaderBlock(const BalsaHeaders& headers,
+ const string& scheme,
+ const string& host_and_port,
+ const string& path,
+ SpdyHeaderBlock* block) {
+ PopulateSpdyHeaderBlock(headers, block, true);
+ StringPiece host_header = headers.GetHeader("Host");
+ if (!host_header.empty()) {
+ DCHECK(host_and_port.empty() || host_header == host_and_port);
+ block->insert(make_pair(kV4Host, host_header.as_string()));
+ // PopulateSpdyHeaderBlock already added the "host" header,
+ // which is invalid for SPDY4.
+ block->erase("host");
+ } else {
+ 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
+ }
+ block->insert(make_pair(kV3Path, path));
+ block->insert(make_pair(kV3Scheme, scheme));
+
+ if (!headers.request_method().empty()) {
+ block->insert(make_pair(kV3Method, headers.request_method().as_string()));
+ }
+}
+
void PopulateSpdyResponseHeaderBlock(const BalsaHeaders& headers,
SpdyHeaderBlock* block) {
string status = headers.response_code().as_string();
@@ -134,6 +161,43 @@ SpdyHeaderBlock SpdyUtils::RequestHeadersToSpdyHeaders(
}
// static
+SpdyHeaderBlock SpdyUtils::RequestHeadersToSpdy4Headers(
+ const BalsaHeaders& request_headers) {
+ string scheme;
+ string host_and_port;
+ string path;
+
+ string url = request_headers.request_uri().as_string();
+ if (url.empty() || url[0] == '/') {
+ path = url;
+ } else {
+ GURL request_uri(url);
+ if (request_headers.request_method() == "CONNECT") {
+ path = url;
+ } else {
+ path = request_uri.path();
+ if (!request_uri.query().empty()) {
+ path = path + "?" + request_uri.query();
+ }
+ host_and_port = request_uri.host();
+ scheme = request_uri.scheme();
+ }
+ }
+
+ DCHECK(!scheme.empty());
+ DCHECK(!host_and_port.empty());
+ DCHECK(!path.empty());
+
+ SpdyHeaderBlock block;
+ PopulateSpdy4RequestHeaderBlock(request_headers, scheme, host_and_port, path,
+ &block);
+ if (block.find("host") != block.end()) {
+ block.erase(block.find("host"));
+ }
+ return block;
+}
+
+// static
string SpdyUtils::SerializeRequestHeaders(const BalsaHeaders& request_headers) {
SpdyHeaderBlock block = RequestHeadersToSpdyHeaders(request_headers);
return SerializeUncompressedHeaders(block);

Powered by Google App Engine
This is Rietveld 408576698