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

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

Issue 1129983003: Handle HTTP-Version information as per RFC2616 sec 3.1 references. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments Created 5 years, 7 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
« no previous file with comments | « no previous file | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 621
622 // Note: this implementation implicitly assumes that line_end points at a valid 622 // Note: this implementation implicitly assumes that line_end points at a valid
623 // sentinel character (such as '\0'). 623 // sentinel character (such as '\0').
624 // static 624 // static
625 HttpVersion HttpResponseHeaders::ParseVersion( 625 HttpVersion HttpResponseHeaders::ParseVersion(
626 std::string::const_iterator line_begin, 626 std::string::const_iterator line_begin,
627 std::string::const_iterator line_end) { 627 std::string::const_iterator line_end) {
628 std::string::const_iterator p = line_begin; 628 std::string::const_iterator p = line_begin;
629 629
630 // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT 630 // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
631 // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1). 631 // 1*DIGIT means one or more digits.
632 // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1. 632 // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1.
633 633
634 if ((line_end - p < 4) || !LowerCaseEqualsASCII(p, p + 4, "http")) { 634 if ((line_end - p < 4) || !LowerCaseEqualsASCII(p, p + 4, "http")) {
635 DVLOG(1) << "missing status line"; 635 DVLOG(1) << "missing status line";
636 return HttpVersion(); 636 return HttpVersion();
637 } 637 }
638 638
639 p += 4; 639 p += 4;
640 640
641 if (p >= line_end || *p != '/') { 641 if (p >= line_end || *p != '/') {
642 DVLOG(1) << "missing version"; 642 DVLOG(1) << "missing version";
643 return HttpVersion(); 643 return HttpVersion();
644 } 644 }
645 645
646 std::string::const_iterator dot = std::find(p, line_end, '.'); 646 std::string::const_iterator dot = std::find(p, line_end, '.');
647 if (dot == line_end) { 647 if (dot == line_end) {
648 DVLOG(1) << "malformed version"; 648 DVLOG(1) << "malformed version";
649 return HttpVersion(); 649 return HttpVersion();
650 } 650 }
651 651
652 ++p; // from / to first digit. 652 ++p; // from / to dot digits.
653 ++dot; // from . to second digit.
654 653
655 if (!(*p >= '0' && *p <= '9' && *dot >= '0' && *dot <= '9')) { 654 std::string::const_iterator version_major = p;
655 // std::string version_major = "";
656 for (; version_major != dot; ++version_major) {
657 if (!(*version_major >= '0' && *version_major <= '9')) {
658 DVLOG(1) << "malformed version number";
659 return HttpVersion();
660 }
661 }
662
663 ++dot; // from . to end digits.
664
665 if (!(*dot >= '0' && *dot <= '9')) {
656 DVLOG(1) << "malformed version number"; 666 DVLOG(1) << "malformed version number";
657 return HttpVersion(); 667 return HttpVersion();
658 } 668 }
659 669
660 uint16 major = *p - '0'; 670 // std::string version_minor = "";
661 uint16 minor = *dot - '0'; 671 std::string::const_iterator version_minor = dot;
672 for (; (*version_minor >= '0' && *version_minor <= '9'); ++version_minor) {
673 // version_minor += *dot;
674 }
675 uint major_version_number, minor_version_number;
676 if (!base::StringToUint(StringPiece(p, version_major), &major_version_number))
677 return HttpVersion();
678 if (!base::StringToUint(StringPiece(dot, version_minor),
679 &minor_version_number))
680 return HttpVersion();
681 if (major_version_number > UINT16_MAX || minor_version_number > UINT16_MAX) {
682 DVLOG(1) << "malformed version number";
683 return HttpVersion();
684 }
685
686 uint16 major = static_cast<uint16>(major_version_number);
687 uint16 minor = static_cast<uint16>(minor_version_number);
662 688
663 return HttpVersion(major, minor); 689 return HttpVersion(major, minor);
664 } 690 }
665 691
666 // Note: this implementation implicitly assumes that line_end points at a valid 692 // Note: this implementation implicitly assumes that line_end points at a valid
667 // sentinel character (such as '\0'). 693 // sentinel character (such as '\0').
668 void HttpResponseHeaders::ParseStatusLine( 694 void HttpResponseHeaders::ParseStatusLine(
669 std::string::const_iterator line_begin, 695 std::string::const_iterator line_begin,
670 std::string::const_iterator line_end, 696 std::string::const_iterator line_end,
671 bool has_headers) { 697 bool has_headers) {
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 return true; 1470 return true;
1445 } 1471 }
1446 1472
1447 bool HttpResponseHeaders::IsChunkEncoded() const { 1473 bool HttpResponseHeaders::IsChunkEncoded() const {
1448 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1474 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1449 return GetHttpVersion() >= HttpVersion(1, 1) && 1475 return GetHttpVersion() >= HttpVersion(1, 1) &&
1450 HasHeaderValue("Transfer-Encoding", "chunked"); 1476 HasHeaderValue("Transfer-Encoding", "chunked");
1451 } 1477 }
1452 1478
1453 } // namespace net 1479 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698