| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 response->headers = new HttpResponseHeaders(raw_headers); | 73 response->headers = new HttpResponseHeaders(raw_headers); |
| 74 response->was_fetched_via_spdy = true; | 74 response->was_fetched_via_spdy = true; |
| 75 return true; | 75 return true; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, | 78 void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, |
| 79 const HttpRequestHeaders& request_headers, | 79 const HttpRequestHeaders& request_headers, |
| 80 spdy::SpdyHeaderBlock* headers, | 80 spdy::SpdyHeaderBlock* headers, |
| 81 int protocol_version, |
| 81 bool direct) { | 82 bool direct) { |
| 82 | 83 |
| 83 HttpRequestHeaders::Iterator it(request_headers); | 84 HttpRequestHeaders::Iterator it(request_headers); |
| 84 while (it.GetNext()) { | 85 while (it.GetNext()) { |
| 85 std::string name = StringToLowerASCII(it.name()); | 86 std::string name = StringToLowerASCII(it.name()); |
| 86 if (name == "connection" || name == "proxy-connection" || | 87 if (name == "connection" || name == "proxy-connection" || |
| 87 name == "transfer-encoding") { | 88 name == "transfer-encoding") { |
| 88 continue; | 89 continue; |
| 89 } | 90 } |
| 90 if (headers->find(name) == headers->end()) { | 91 if (headers->find(name) == headers->end()) { |
| 91 (*headers)[name] = it.value(); | 92 (*headers)[name] = it.value(); |
| 92 } else { | 93 } else { |
| 93 std::string new_value = (*headers)[name]; | 94 std::string new_value = (*headers)[name]; |
| 94 new_value.append(1, '\0'); // +=() doesn't append 0's | 95 new_value.append(1, '\0'); // +=() doesn't append 0's |
| 95 new_value += it.value(); | 96 new_value += it.value(); |
| 96 (*headers)[name] = new_value; | 97 (*headers)[name] = new_value; |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 static const char kHttpProtocolVersion[] = "HTTP/1.1"; | 100 static const char kHttpProtocolVersion[] = "HTTP/1.1"; |
| 100 | 101 |
| 101 (*headers)["version"] = kHttpProtocolVersion; | 102 if (protocol_version < 3) { |
| 102 (*headers)["method"] = info.method; | 103 (*headers)["version"] = kHttpProtocolVersion; |
| 103 (*headers)["host"] = GetHostAndOptionalPort(info.url); | 104 (*headers)["method"] = info.method; |
| 104 (*headers)["scheme"] = info.url.scheme(); | 105 (*headers)["host"] = GetHostAndOptionalPort(info.url); |
| 105 if (direct) | 106 (*headers)["scheme"] = info.url.scheme(); |
| 106 (*headers)["url"] = HttpUtil::PathForRequest(info.url); | 107 if (direct) |
| 107 else | 108 (*headers)["url"] = HttpUtil::PathForRequest(info.url); |
| 108 (*headers)["url"] = HttpUtil::SpecForRequest(info.url); | 109 else |
| 110 (*headers)["url"] = HttpUtil::SpecForRequest(info.url); |
| 111 } else { |
| 112 (*headers)[":version"] = kHttpProtocolVersion; |
| 113 (*headers)[":method"] = info.method; |
| 114 (*headers)[":host"] = GetHostAndOptionalPort(info.url); |
| 115 (*headers)[":scheme"] = info.url.scheme(); |
| 116 (*headers)[":path"] = HttpUtil::PathForRequest(info.url); |
| 117 headers->erase("host"); // this is kinda insane, spdy 3 spec. |
| 118 } |
| 109 | 119 |
| 110 } | 120 } |
| 111 | 121 |
| 112 // TODO(gavinp): re-adjust this once SPDY v3 has three priority bits, | 122 // TODO(gavinp): re-adjust this once SPDY v3 has three priority bits, |
| 113 // eliminating the need for this folding. | 123 // eliminating the need for this folding. |
| 114 int ConvertRequestPriorityToSpdyPriority(const RequestPriority priority) { | 124 int ConvertRequestPriorityToSpdyPriority(const RequestPriority priority) { |
| 115 DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES); | 125 DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES); |
| 116 switch (priority) { | 126 switch (priority) { |
| 117 case LOWEST: | 127 case LOWEST: |
| 118 return SPDY_PRIORITY_LOWEST - 1; | 128 return SPDY_PRIORITY_LOWEST - 1; |
| 119 case IDLE: | 129 case IDLE: |
| 120 return SPDY_PRIORITY_LOWEST; | 130 return SPDY_PRIORITY_LOWEST; |
| 121 default: | 131 default: |
| 122 return priority; | 132 return priority; |
| 123 } | 133 } |
| 124 } | 134 } |
| 125 | 135 |
| 126 } // namespace net | 136 } // namespace net |
| OLD | NEW |