Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: net/http/http_response_headers.cc

Issue 1594973004: Remove use of void** from HttpResponseHeaders::EnumerateHeaderLines (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(':');
327 new_raw_headers.push_back(' '); 327 new_raw_headers.push_back(' ');
328 new_raw_headers.append(old_header_value); 328 new_raw_headers.append(old_header_value);
329 new_raw_headers.push_back('\0'); 329 new_raw_headers.push_back('\0');
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
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& i,
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);
556 if (i == parsed_.size()) 555 if (i == parsed_.size())
557 return false; 556 return false;
558 557
559 DCHECK(!parsed_[i].is_continuation()); 558 DCHECK(!parsed_[i].is_continuation());
560 559
561 name->assign(parsed_[i].name_begin, parsed_[i].name_end); 560 name->assign(parsed_[i].name_begin, parsed_[i].name_end);
562 561
563 std::string::const_iterator value_begin = parsed_[i].value_begin; 562 std::string::const_iterator value_begin = parsed_[i].value_begin;
564 std::string::const_iterator value_end = parsed_[i].value_end; 563 std::string::const_iterator value_end = parsed_[i].value_end;
565 while (++i < parsed_.size() && parsed_[i].is_continuation()) 564 while (++i < parsed_.size() && parsed_[i].is_continuation())
566 value_end = parsed_[i].value_end; 565 value_end = parsed_[i].value_end;
567 566
568 value->assign(value_begin, value_end); 567 value->assign(value_begin, value_end);
569 568
570 *iter = reinterpret_cast<void*>(i);
571 return true; 569 return true;
572 } 570 }
573 571
574 bool HttpResponseHeaders::EnumerateHeader(void** iter, 572 bool HttpResponseHeaders::EnumerateHeader(void** iter,
575 const base::StringPiece& name, 573 const base::StringPiece& name,
576 std::string* value) const { 574 std::string* value) const {
577 size_t i; 575 size_t i;
578 if (!iter || !*iter) { 576 if (!iter || !*iter) {
579 i = FindHeader(0, name); 577 i = FindHeader(0, name);
580 } else { 578 } else {
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 return false; 1385 return false;
1388 1386
1389 return true; 1387 return true;
1390 } 1388 }
1391 1389
1392 scoped_ptr<base::Value> HttpResponseHeaders::NetLogCallback( 1390 scoped_ptr<base::Value> HttpResponseHeaders::NetLogCallback(
1393 NetLogCaptureMode capture_mode) const { 1391 NetLogCaptureMode capture_mode) const {
1394 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 1392 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
1395 base::ListValue* headers = new base::ListValue(); 1393 base::ListValue* headers = new base::ListValue();
1396 headers->Append(new base::StringValue(GetStatusLine())); 1394 headers->Append(new base::StringValue(GetStatusLine()));
1397 void* iterator = NULL; 1395 size_t iterator = 0;
1398 std::string name; 1396 std::string name;
1399 std::string value; 1397 std::string value;
1400 while (EnumerateHeaderLines(&iterator, &name, &value)) { 1398 while (EnumerateHeaderLines(iterator, &name, &value)) {
1401 std::string log_value = 1399 std::string log_value =
1402 ElideHeaderValueForNetLog(capture_mode, name, value); 1400 ElideHeaderValueForNetLog(capture_mode, name, value);
1403 std::string escaped_name = EscapeNonASCII(name); 1401 std::string escaped_name = EscapeNonASCII(name);
1404 std::string escaped_value = EscapeNonASCII(log_value); 1402 std::string escaped_value = EscapeNonASCII(log_value);
1405 headers->Append( 1403 headers->Append(
1406 new base::StringValue( 1404 new base::StringValue(
1407 base::StringPrintf("%s: %s", escaped_name.c_str(), 1405 base::StringPrintf("%s: %s", escaped_name.c_str(),
1408 escaped_value.c_str()))); 1406 escaped_value.c_str())));
1409 } 1407 }
1410 dict->Set("headers", headers); 1408 dict->Set("headers", headers);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 return true; 1440 return true;
1443 } 1441 }
1444 1442
1445 bool HttpResponseHeaders::IsChunkEncoded() const { 1443 bool HttpResponseHeaders::IsChunkEncoded() const {
1446 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1444 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1447 return GetHttpVersion() >= HttpVersion(1, 1) && 1445 return GetHttpVersion() >= HttpVersion(1, 1) &&
1448 HasHeaderValue("Transfer-Encoding", "chunked"); 1446 HasHeaderValue("Transfer-Encoding", "chunked");
1449 } 1447 }
1450 1448
1451 } // namespace net 1449 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698