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

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

Issue 14651009: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integer constant is too large for 'unsigned long' type Created 7 years, 7 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/tools/quic/spdy_utils.h ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('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/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/string_util.h" 10 #include "base/string_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 status.append(" "); 89 status.append(" ");
90 status.append(headers.response_reason_phrase().as_string()); 90 status.append(headers.response_reason_phrase().as_string());
91 (*block)[kV3Status] = status; 91 (*block)[kV3Status] = status;
92 (*block)[kV3Version] = 92 (*block)[kV3Version] =
93 headers.response_version().as_string(); 93 headers.response_version().as_string();
94 94
95 // Empty header values are only allowed because this is spdy3. 95 // Empty header values are only allowed because this is spdy3.
96 PopulateSpdyHeaderBlock(headers, block, true); 96 PopulateSpdyHeaderBlock(headers, block, true);
97 } 97 }
98 98
99 string SpdyUtils::SerializeRequestHeaders( 99 // static
100 SpdyHeaderBlock SpdyUtils::RequestHeadersToSpdyHeaders(
100 const BalsaHeaders& request_headers) { 101 const BalsaHeaders& request_headers) {
101 string scheme; 102 string scheme;
102 string host_and_port; 103 string host_and_port;
103 string path; 104 string path;
104 105
105 string url = request_headers.request_uri().as_string(); 106 string url = request_headers.request_uri().as_string();
106 if (url.empty() || url[0] == '/') { 107 if (url.empty() || url[0] == '/') {
107 path = url; 108 path = url;
108 } else { 109 } else {
109 GURL request_uri(url); 110 GURL request_uri(url);
(...skipping 12 matching lines...) Expand all
122 DCHECK(!scheme.empty()); 123 DCHECK(!scheme.empty());
123 DCHECK(!host_and_port.empty()); 124 DCHECK(!host_and_port.empty());
124 DCHECK(!path.empty()); 125 DCHECK(!path.empty());
125 126
126 SpdyHeaderBlock block; 127 SpdyHeaderBlock block;
127 PopulateSpdy3RequestHeaderBlock( 128 PopulateSpdy3RequestHeaderBlock(
128 request_headers, scheme, host_and_port, path, &block); 129 request_headers, scheme, host_and_port, path, &block);
129 if (block.find("host") != block.end()) { 130 if (block.find("host") != block.end()) {
130 block.erase(block.find("host")); 131 block.erase(block.find("host"));
131 } 132 }
132 133 return block;
133 int length = SpdyFramer::GetSerializedLength(kSpdyVersion3, &block);
134 SpdyFrameBuilder builder(length);
135 SpdyFramer::WriteHeaderBlock(&builder, kSpdyVersion3, &block);
136 scoped_ptr<SpdyFrame> headers(builder.take());
137 return string(headers->data(), length);
138 } 134 }
139 135
140 string SpdyUtils::SerializeResponseHeaders( 136 // static
137 string SpdyUtils::SerializeRequestHeaders(const BalsaHeaders& request_headers) {
138 SpdyHeaderBlock block = RequestHeadersToSpdyHeaders(request_headers);
139 return SerializeUncompressedHeaders(block);
140 }
141
142 // static
143 SpdyHeaderBlock SpdyUtils::ResponseHeadersToSpdyHeaders(
141 const BalsaHeaders& response_headers) { 144 const BalsaHeaders& response_headers) {
142 SpdyHeaderBlock block; 145 SpdyHeaderBlock block;
143 PopulateSpdyResponseHeaderBlock(response_headers, &block); 146 PopulateSpdyResponseHeaderBlock(response_headers, &block);
147 return block;
148 }
144 149
145 int length = SpdyFramer::GetSerializedLength(kSpdyVersion3, &block); 150 // static
151 string SpdyUtils::SerializeResponseHeaders(
152 const BalsaHeaders& response_headers) {
153 SpdyHeaderBlock block = ResponseHeadersToSpdyHeaders(response_headers);
154
155 return SerializeUncompressedHeaders(block);
156 }
157
158 // static
159 string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) {
160 int length = SpdyFramer::GetSerializedLength(kSpdyVersion3, &headers);
146 SpdyFrameBuilder builder(length); 161 SpdyFrameBuilder builder(length);
147 SpdyFramer::WriteHeaderBlock(&builder, kSpdyVersion3, &block); 162 SpdyFramer::WriteHeaderBlock(&builder, kSpdyVersion3, &headers);
148 scoped_ptr<SpdyFrame> headers(builder.take()); 163 scoped_ptr<SpdyFrame> block(builder.take());
149 return string(headers->data(), length); 164 return string(block->data(), length);
150 } 165 }
151 166
152 bool IsSpecialSpdyHeader(SpdyHeaderBlock::const_iterator header, 167 bool IsSpecialSpdyHeader(SpdyHeaderBlock::const_iterator header,
153 BalsaHeaders* headers) { 168 BalsaHeaders* headers) {
154 if (header->first.empty() || header->second.empty()) { 169 if (header->first.empty() || header->second.empty()) {
155 return true; 170 return true;
156 } 171 }
157 const string& header_name = header->first; 172 const string& header_name = header->first;
158 return header_name.c_str()[0] == ':'; 173 return header_name.c_str()[0] == ':';
159 } 174 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) { 257 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) {
243 if (!IsSpecialSpdyHeader(it, request_headers)) { 258 if (!IsSpecialSpdyHeader(it, request_headers)) {
244 request_headers->AppendHeader(it->first, it->second); 259 request_headers->AppendHeader(it->first, it->second);
245 } 260 }
246 } 261 }
247 return true; 262 return true;
248 } 263 }
249 264
250 } // namespace tools 265 } // namespace tools
251 } // namespace net 266 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/spdy_utils.h ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698