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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 306 |
307 void HttpResponseHeaders::RemoveHeaderLine(const std::string& name, | 307 void HttpResponseHeaders::RemoveHeaderLine(const std::string& name, |
308 const std::string& value) { | 308 const std::string& value) { |
309 std::string name_lowercase = base::ToLowerASCII(name); | 309 std::string name_lowercase = base::ToLowerASCII(name); |
310 | 310 |
311 std::string new_raw_headers(GetStatusLine()); | 311 std::string new_raw_headers(GetStatusLine()); |
312 new_raw_headers.push_back('\0'); | 312 new_raw_headers.push_back('\0'); |
313 | 313 |
314 new_raw_headers.reserve(raw_headers_.size()); | 314 new_raw_headers.reserve(raw_headers_.size()); |
315 | 315 |
316 void* iter = NULL; | 316 size_t iter = 0; |
317 std::string old_header_name; | 317 std::string old_header_name; |
318 std::string old_header_value; | 318 std::string old_header_value; |
319 while (EnumerateHeaderLines(&iter, &old_header_name, &old_header_value)) { | 319 while (EnumerateHeaderLines(&iter, &old_header_name, &old_header_value)) { |
320 std::string old_header_name_lowercase = base::ToLowerASCII(old_header_name); | 320 std::string old_header_name_lowercase = base::ToLowerASCII(old_header_name); |
321 if (name_lowercase == old_header_name_lowercase && | 321 if (name_lowercase == old_header_name_lowercase && |
322 value == old_header_value) | 322 value == old_header_value) |
323 continue; | 323 continue; |
324 | 324 |
325 new_raw_headers.append(old_header_name); | 325 new_raw_headers.append(old_header_name); |
326 new_raw_headers.push_back(':'); | 326 new_raw_headers.push_back(':'); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 CHECK(begin != end); | 542 CHECK(begin != end); |
543 // See if there is another space. | 543 // See if there is another space. |
544 begin = std::find(begin, end, ' '); | 544 begin = std::find(begin, end, ' '); |
545 if (begin == end) | 545 if (begin == end) |
546 return std::string(); | 546 return std::string(); |
547 ++begin; | 547 ++begin; |
548 CHECK(begin != end); | 548 CHECK(begin != end); |
549 return std::string(begin, end); | 549 return std::string(begin, end); |
550 } | 550 } |
551 | 551 |
552 bool HttpResponseHeaders::EnumerateHeaderLines(void** iter, | 552 bool HttpResponseHeaders::EnumerateHeaderLines(size_t* iter, |
553 std::string* name, | 553 std::string* name, |
554 std::string* value) const { | 554 std::string* value) const { |
555 size_t i = reinterpret_cast<size_t>(*iter); | 555 size_t i = *iter; |
556 if (i == parsed_.size()) | 556 if (i == parsed_.size()) |
557 return false; | 557 return false; |
558 | 558 |
559 DCHECK(!parsed_[i].is_continuation()); | 559 DCHECK(!parsed_[i].is_continuation()); |
560 | 560 |
561 name->assign(parsed_[i].name_begin, parsed_[i].name_end); | 561 name->assign(parsed_[i].name_begin, parsed_[i].name_end); |
562 | 562 |
563 std::string::const_iterator value_begin = parsed_[i].value_begin; | 563 std::string::const_iterator value_begin = parsed_[i].value_begin; |
564 std::string::const_iterator value_end = parsed_[i].value_end; | 564 std::string::const_iterator value_end = parsed_[i].value_end; |
565 while (++i < parsed_.size() && parsed_[i].is_continuation()) | 565 while (++i < parsed_.size() && parsed_[i].is_continuation()) |
566 value_end = parsed_[i].value_end; | 566 value_end = parsed_[i].value_end; |
567 | 567 |
568 value->assign(value_begin, value_end); | 568 value->assign(value_begin, value_end); |
569 | 569 |
570 *iter = reinterpret_cast<void*>(i); | 570 *iter = i; |
571 return true; | 571 return true; |
572 } | 572 } |
573 | 573 |
574 bool HttpResponseHeaders::EnumerateHeader(void** iter, | 574 bool HttpResponseHeaders::EnumerateHeader(void** iter, |
575 const base::StringPiece& name, | 575 const base::StringPiece& name, |
576 std::string* value) const { | 576 std::string* value) const { |
577 size_t i; | 577 size_t i; |
578 if (!iter || !*iter) { | 578 if (!iter || !*iter) { |
579 i = FindHeader(0, name); | 579 i = FindHeader(0, name); |
580 } else { | 580 } else { |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 return false; | 1387 return false; |
1388 | 1388 |
1389 return true; | 1389 return true; |
1390 } | 1390 } |
1391 | 1391 |
1392 scoped_ptr<base::Value> HttpResponseHeaders::NetLogCallback( | 1392 scoped_ptr<base::Value> HttpResponseHeaders::NetLogCallback( |
1393 NetLogCaptureMode capture_mode) const { | 1393 NetLogCaptureMode capture_mode) const { |
1394 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 1394 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
1395 base::ListValue* headers = new base::ListValue(); | 1395 base::ListValue* headers = new base::ListValue(); |
1396 headers->Append(new base::StringValue(GetStatusLine())); | 1396 headers->Append(new base::StringValue(GetStatusLine())); |
1397 void* iterator = NULL; | 1397 size_t iterator = 0; |
1398 std::string name; | 1398 std::string name; |
1399 std::string value; | 1399 std::string value; |
1400 while (EnumerateHeaderLines(&iterator, &name, &value)) { | 1400 while (EnumerateHeaderLines(&iterator, &name, &value)) { |
1401 std::string log_value = | 1401 std::string log_value = |
1402 ElideHeaderValueForNetLog(capture_mode, name, value); | 1402 ElideHeaderValueForNetLog(capture_mode, name, value); |
1403 std::string escaped_name = EscapeNonASCII(name); | 1403 std::string escaped_name = EscapeNonASCII(name); |
1404 std::string escaped_value = EscapeNonASCII(log_value); | 1404 std::string escaped_value = EscapeNonASCII(log_value); |
1405 headers->Append( | 1405 headers->Append( |
1406 new base::StringValue( | 1406 new base::StringValue( |
1407 base::StringPrintf("%s: %s", escaped_name.c_str(), | 1407 base::StringPrintf("%s: %s", escaped_name.c_str(), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 return true; | 1442 return true; |
1443 } | 1443 } |
1444 | 1444 |
1445 bool HttpResponseHeaders::IsChunkEncoded() const { | 1445 bool HttpResponseHeaders::IsChunkEncoded() const { |
1446 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1446 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
1447 return GetHttpVersion() >= HttpVersion(1, 1) && | 1447 return GetHttpVersion() >= HttpVersion(1, 1) && |
1448 HasHeaderValue("Transfer-Encoding", "chunked"); | 1448 HasHeaderValue("Transfer-Encoding", "chunked"); |
1449 } | 1449 } |
1450 | 1450 |
1451 } // namespace net | 1451 } // namespace net |
OLD | NEW |