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" |
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 | 1384 |
1385 // We have all the values; let's verify that they make sense for a 206 | 1385 // We have all the values; let's verify that they make sense for a 206 |
1386 // response. | 1386 // response. |
1387 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1387 if (*first_byte_position < 0 || *last_byte_position < 0 || |
1388 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | 1388 *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
1389 return false; | 1389 return false; |
1390 | 1390 |
1391 return true; | 1391 return true; |
1392 } | 1392 } |
1393 | 1393 |
1394 base::Value* HttpResponseHeaders::NetLogCallback( | 1394 scoped_ptr<base::Value> HttpResponseHeaders::NetLogCallback( |
1395 NetLogCaptureMode capture_mode) const { | 1395 NetLogCaptureMode capture_mode) const { |
1396 base::DictionaryValue* dict = new base::DictionaryValue(); | 1396 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
1397 base::ListValue* headers = new base::ListValue(); | 1397 scoped_ptr<base::ListValue> headers(new base::ListValue()); |
1398 headers->Append(new base::StringValue(GetStatusLine())); | 1398 headers->Append(new base::StringValue(GetStatusLine())); |
1399 void* iterator = NULL; | 1399 void* iterator = NULL; |
1400 std::string name; | 1400 std::string name; |
1401 std::string value; | 1401 std::string value; |
1402 while (EnumerateHeaderLines(&iterator, &name, &value)) { | 1402 while (EnumerateHeaderLines(&iterator, &name, &value)) { |
1403 std::string log_value = | 1403 std::string log_value = |
1404 ElideHeaderValueForNetLog(capture_mode, name, value); | 1404 ElideHeaderValueForNetLog(capture_mode, name, value); |
1405 std::string escaped_name = EscapeNonASCII(name); | 1405 std::string escaped_name = EscapeNonASCII(name); |
1406 std::string escaped_value = EscapeNonASCII(log_value); | 1406 std::string escaped_value = EscapeNonASCII(log_value); |
1407 headers->Append( | 1407 headers->Append( |
1408 new base::StringValue( | 1408 new base::StringValue( |
1409 base::StringPrintf("%s: %s", escaped_name.c_str(), | 1409 base::StringPrintf("%s: %s", escaped_name.c_str(), |
1410 escaped_value.c_str()))); | 1410 escaped_value.c_str()))); |
1411 } | 1411 } |
1412 dict->Set("headers", headers); | 1412 dict->Set("headers", headers.Pass()); |
1413 return dict; | 1413 return dict.Pass(); |
1414 } | 1414 } |
1415 | 1415 |
1416 // static | 1416 // static |
1417 bool HttpResponseHeaders::FromNetLogParam( | 1417 bool HttpResponseHeaders::FromNetLogParam( |
1418 const base::Value* event_param, | 1418 const base::Value* event_param, |
1419 scoped_refptr<HttpResponseHeaders>* http_response_headers) { | 1419 scoped_refptr<HttpResponseHeaders>* http_response_headers) { |
1420 *http_response_headers = NULL; | 1420 *http_response_headers = NULL; |
1421 | 1421 |
1422 const base::DictionaryValue* dict = NULL; | 1422 const base::DictionaryValue* dict = NULL; |
1423 const base::ListValue* header_list = NULL; | 1423 const base::ListValue* header_list = NULL; |
(...skipping 20 matching lines...) Expand all Loading... |
1444 return true; | 1444 return true; |
1445 } | 1445 } |
1446 | 1446 |
1447 bool HttpResponseHeaders::IsChunkEncoded() const { | 1447 bool HttpResponseHeaders::IsChunkEncoded() const { |
1448 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1448 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
1449 return GetHttpVersion() >= HttpVersion(1, 1) && | 1449 return GetHttpVersion() >= HttpVersion(1, 1) && |
1450 HasHeaderValue("Transfer-Encoding", "chunked"); | 1450 HasHeaderValue("Transfer-Encoding", "chunked"); |
1451 } | 1451 } |
1452 | 1452 |
1453 } // namespace net | 1453 } // namespace net |
OLD | NEW |