OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/quic/core/spdy_utils.h" | 5 #include "net/quic/core/spdy_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 string SpdyUtils::GetHostNameFromHeaderBlock(const SpdyHeaderBlock& headers) { | 235 string SpdyUtils::GetHostNameFromHeaderBlock(const SpdyHeaderBlock& headers) { |
236 return GURL(GetUrlFromHeaderBlock(headers)).host(); | 236 return GURL(GetUrlFromHeaderBlock(headers)).host(); |
237 } | 237 } |
238 | 238 |
239 // static | 239 // static |
240 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) { | 240 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) { |
241 string url(GetUrlFromHeaderBlock(headers)); | 241 string url(GetUrlFromHeaderBlock(headers)); |
242 return url != "" && GURL(url).is_valid(); | 242 return url != "" && GURL(url).is_valid(); |
243 } | 243 } |
244 | 244 |
| 245 // static |
| 246 bool SpdyUtils::PopulateHeaderBlockFromUrl(const string url, |
| 247 SpdyHeaderBlock* headers) { |
| 248 (*headers)[":method"] = "GET"; |
| 249 size_t pos = url.find("://"); |
| 250 if (pos == string::npos) { |
| 251 return false; |
| 252 } |
| 253 (*headers)[":scheme"] = url.substr(0, pos); |
| 254 size_t start = pos + 3; |
| 255 pos = url.find("/", start); |
| 256 if (pos == string::npos) { |
| 257 return false; |
| 258 } |
| 259 (*headers)[":authority"] = url.substr(start, pos - start); |
| 260 (*headers)[":path"] = url.substr(pos); |
| 261 return true; |
| 262 } |
| 263 |
245 } // namespace net | 264 } // namespace net |
OLD | NEW |