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

Unified Diff: net/spdy/spdy_http_utils.cc

Issue 337093003: QuicServer: Use Chrome's header parsing rather than Balsa (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quic_server_3
Patch Set: Small cleanup Created 6 years, 6 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/spdy/spdy_http_utils.cc
diff --git a/net/spdy/spdy_http_utils.cc b/net/spdy/spdy_http_utils.cc
index 448c82ffd3ca9a2fc06f947f706e6082c36f8956..cc0cab415dd35466afd3fa23804093e00ad85564 100644
--- a/net/spdy/spdy_http_utils.cc
+++ b/net/spdy/spdy_http_utils.cc
@@ -20,6 +20,20 @@
namespace net {
+namespace {
+
+void AddSpdyHeader(SpdyHeaderBlock* headers,
+ const std::string& name,
+ const std::string& value) {
+ if (headers->find(name) == headers->end()) {
+ (*headers)[name] = value;
+ } else {
+ (*headers)[name] += '\0' + value;
+ }
+}
+
+} // namespace
+
bool SpdyHeadersToHttpResponse(const SpdyHeaderBlock& headers,
SpdyMajorVersion protocol_version,
HttpResponseInfo* response) {
@@ -85,9 +99,9 @@ bool SpdyHeadersToHttpResponse(const SpdyHeaderBlock& headers,
void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info,
const HttpRequestHeaders& request_headers,
- SpdyHeaderBlock* headers,
SpdyMajorVersion protocol_version,
- bool direct) {
+ bool direct,
+ SpdyHeaderBlock* headers) {
HttpRequestHeaders::Iterator it(request_headers);
while (it.GetNext()) {
@@ -96,14 +110,7 @@ void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info,
name == "transfer-encoding" || name == "host") {
continue;
}
- if (headers->find(name) == headers->end()) {
- (*headers)[name] = it.value();
- } else {
- std::string new_value = (*headers)[name];
- new_value.append(1, '\0'); // +=() doesn't append 0's
- new_value += it.value();
- (*headers)[name] = new_value;
- }
+ AddSpdyHeader(headers, name, it.value());
}
static const char kHttpProtocolVersion[] = "HTTP/1.1";
@@ -129,6 +136,31 @@ void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info,
}
}
+void CreateSpdyHeadersFromHttpResponse(
+ const HttpResponseHeaders& response_headers,
+ SpdyMajorVersion protocol_version,
+ SpdyHeaderBlock* headers) {
+ std::string status_key = (protocol_version >= SPDY3) ? ":status" : "status";
+ std::string version_key =
+ (protocol_version >= SPDY3) ? ":version" : "version";
+
+ std::string status_line = response_headers.GetStatusLine();
+ std::string::const_iterator after_version =
+ std::find(status_line.begin(), status_line.end(), ' ');
+ if (protocol_version < SPDY4) {
+ (*headers)[version_key] = std::string(status_line.cbegin(), after_version);
+ }
+ (*headers)[status_key] = std::string(after_version + 1, status_line.cend());
+
+ void* iter = NULL;
+ std::string raw_name, value;
+ while (response_headers.EnumerateHeaderLines(&iter, &raw_name, &value)) {
+ std::string name = StringToLowerASCII(raw_name);
+ AddSpdyHeader(headers, name, value);
+ }
+}
+
+
COMPILE_ASSERT(HIGHEST - LOWEST < 4 &&
HIGHEST - MINIMUM_PRIORITY < 5,
request_priority_incompatible_with_spdy);

Powered by Google App Engine
This is Rietveld 408576698