| OLD | NEW |
| 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 // The rules for header parsing were borrowed from Firefox: | 5 // The rules for header parsing were borrowed from Firefox: |
| 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo
nseHead.cpp | 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo
nseHead.cpp |
| 7 // The rules for parsing content-types were also borrowed from Firefox: | 7 // The rules for parsing content-types were also borrowed from Firefox: |
| 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 | 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 |
| 9 | 9 |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/pickle.h" | 16 #include "base/pickle.h" |
| 17 #include "base/stringprintf.h" |
| 17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 18 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
| 19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 20 #include "base/time.h" | 21 #include "base/time.h" |
| 22 #include "base/values.h" |
| 21 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
| 22 #include "net/http/http_util.h" | 24 #include "net/http/http_util.h" |
| 23 | 25 |
| 24 using base::StringPiece; | 26 using base::StringPiece; |
| 25 using base::Time; | 27 using base::Time; |
| 26 using base::TimeDelta; | 28 using base::TimeDelta; |
| 27 | 29 |
| 28 namespace net { | 30 namespace net { |
| 29 | 31 |
| 30 //----------------------------------------------------------------------------- | 32 //----------------------------------------------------------------------------- |
| (...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 | 1301 |
| 1300 // We have all the values; let's verify that they make sense for a 206 | 1302 // We have all the values; let's verify that they make sense for a 206 |
| 1301 // response. | 1303 // response. |
| 1302 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1304 if (*first_byte_position < 0 || *last_byte_position < 0 || |
| 1303 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | 1305 *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
| 1304 return false; | 1306 return false; |
| 1305 | 1307 |
| 1306 return true; | 1308 return true; |
| 1307 } | 1309 } |
| 1308 | 1310 |
| 1311 Value* HttpResponseHeaders::NetLogCallback( |
| 1312 NetLog::LogLevel /* log_level */) const { |
| 1313 DictionaryValue* dict = new DictionaryValue(); |
| 1314 ListValue* headers = new ListValue(); |
| 1315 headers->Append(new StringValue(GetStatusLine())); |
| 1316 void* iterator = NULL; |
| 1317 std::string name; |
| 1318 std::string value; |
| 1319 while (EnumerateHeaderLines(&iterator, &name, &value)) { |
| 1320 headers->Append( |
| 1321 new StringValue(base::StringPrintf("%s: %s", |
| 1322 name.c_str(), |
| 1323 value.c_str()))); |
| 1324 } |
| 1325 dict->Set("headers", headers); |
| 1326 return dict; |
| 1327 } |
| 1328 |
| 1329 // static |
| 1330 bool HttpResponseHeaders::FromNetLogParam( |
| 1331 const base::Value* event_param, |
| 1332 scoped_refptr<HttpResponseHeaders>* http_response_headers) { |
| 1333 http_response_headers->release(); |
| 1334 |
| 1335 const base::DictionaryValue* dict; |
| 1336 base::ListValue* header_list; |
| 1337 |
| 1338 if (!event_param || |
| 1339 !event_param->GetAsDictionary(&dict) || |
| 1340 !dict->GetList("headers", &header_list)) { |
| 1341 return false; |
| 1342 } |
| 1343 |
| 1344 std::string raw_headers; |
| 1345 for (base::ListValue::const_iterator it = header_list->begin(); |
| 1346 it != header_list->end(); |
| 1347 ++it) { |
| 1348 std::string header_line; |
| 1349 if (!(*it)->GetAsString(&header_line)) |
| 1350 return false; |
| 1351 |
| 1352 raw_headers.append(header_line); |
| 1353 raw_headers.push_back('\0'); |
| 1354 } |
| 1355 raw_headers.push_back('\0'); |
| 1356 *http_response_headers = new HttpResponseHeaders(raw_headers); |
| 1357 return true; |
| 1358 } |
| 1359 |
| 1309 bool HttpResponseHeaders::IsChunkEncoded() const { | 1360 bool HttpResponseHeaders::IsChunkEncoded() const { |
| 1310 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1361 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
| 1311 return GetHttpVersion() >= HttpVersion(1, 1) && | 1362 return GetHttpVersion() >= HttpVersion(1, 1) && |
| 1312 HasHeaderValue("Transfer-Encoding", "chunked"); | 1363 HasHeaderValue("Transfer-Encoding", "chunked"); |
| 1313 } | 1364 } |
| 1314 | 1365 |
| 1315 } // namespace net | 1366 } // namespace net |
| OLD | NEW |