| 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 29 matching lines...) Expand all Loading... |
| 40 bool SpdyUtils::ParseHeaders(const char* data, | 40 bool SpdyUtils::ParseHeaders(const char* data, |
| 41 uint32_t data_len, | 41 uint32_t data_len, |
| 42 int64_t* content_length, | 42 int64_t* content_length, |
| 43 SpdyHeaderBlock* headers) { | 43 SpdyHeaderBlock* headers) { |
| 44 SpdyFramer framer(HTTP2); | 44 SpdyFramer framer(HTTP2); |
| 45 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || | 45 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || |
| 46 headers->empty()) { | 46 headers->empty()) { |
| 47 return false; // Headers were invalid. | 47 return false; // Headers were invalid. |
| 48 } | 48 } |
| 49 | 49 |
| 50 if (ContainsKey(*headers, "content-length")) { | 50 if (base::ContainsKey(*headers, "content-length")) { |
| 51 // Check whether multiple values are consistent. | 51 // Check whether multiple values are consistent. |
| 52 base::StringPiece content_length_header = (*headers)["content-length"]; | 52 base::StringPiece content_length_header = (*headers)["content-length"]; |
| 53 vector<string> values = | 53 vector<string> values = |
| 54 base::SplitString(content_length_header, base::StringPiece("\0", 1), | 54 base::SplitString(content_length_header, base::StringPiece("\0", 1), |
| 55 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 55 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 56 for (const string& value : values) { | 56 for (const string& value : values) { |
| 57 int64_t new_value; | 57 int64_t new_value; |
| 58 if (!base::StringToInt64(value, &new_value) || new_value < 0) { | 58 if (!base::StringToInt64(value, &new_value) || new_value < 0) { |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 s.append("; "); | 142 s.append("; "); |
| 143 } else { | 143 } else { |
| 144 StringPiece("\0", 1).AppendToString(&s); | 144 StringPiece("\0", 1).AppendToString(&s); |
| 145 } | 145 } |
| 146 s.append(p.second); | 146 s.append(p.second); |
| 147 headers->ReplaceOrAppendHeader(name, s); | 147 headers->ReplaceOrAppendHeader(name, s); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 if (ContainsKey(*headers, "content-length")) { | 152 if (base::ContainsKey(*headers, "content-length")) { |
| 153 // Check whether multiple values are consistent. | 153 // Check whether multiple values are consistent. |
| 154 StringPiece content_length_header = (*headers)["content-length"]; | 154 StringPiece content_length_header = (*headers)["content-length"]; |
| 155 vector<string> values = | 155 vector<string> values = |
| 156 base::SplitString(content_length_header, base::StringPiece("\0", 1), | 156 base::SplitString(content_length_header, base::StringPiece("\0", 1), |
| 157 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 157 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 158 for (const string& value : values) { | 158 for (const string& value : values) { |
| 159 int64_t new_value; | 159 int64_t new_value; |
| 160 if (!base::StringToInt64(value, &new_value) || new_value < 0) { | 160 if (!base::StringToInt64(value, &new_value) || new_value < 0) { |
| 161 DLOG(ERROR) << "Content length was either unparseable or negative."; | 161 DLOG(ERROR) << "Content length was either unparseable or negative."; |
| 162 return false; | 162 return false; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return GURL(GetUrlFromHeaderBlock(headers)).host(); | 255 return GURL(GetUrlFromHeaderBlock(headers)).host(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 // static | 258 // static |
| 259 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) { | 259 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) { |
| 260 string url(GetUrlFromHeaderBlock(headers)); | 260 string url(GetUrlFromHeaderBlock(headers)); |
| 261 return url != "" && GURL(url).is_valid(); | 261 return url != "" && GURL(url).is_valid(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace net | 264 } // namespace net |
| OLD | NEW |