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

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

Issue 265603002: Revert of HttpServer: avoid DCHECK'ing on non-HTTP/1.1 requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « net/http/http_response_headers.h ('k') | net/http/http_util.h » ('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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 620 }
621 621
622 HttpResponseHeaders::HttpResponseHeaders() : response_code_(-1) { 622 HttpResponseHeaders::HttpResponseHeaders() : response_code_(-1) {
623 } 623 }
624 624
625 HttpResponseHeaders::~HttpResponseHeaders() { 625 HttpResponseHeaders::~HttpResponseHeaders() {
626 } 626 }
627 627
628 // Note: this implementation implicitly assumes that line_end points at a valid 628 // Note: this implementation implicitly assumes that line_end points at a valid
629 // sentinel character (such as '\0'). 629 // sentinel character (such as '\0').
630 // static
631 HttpVersion HttpResponseHeaders::ParseVersion(
632 std::string::const_iterator line_begin,
633 std::string::const_iterator line_end) {
634 std::string::const_iterator p = line_begin;
635
636 // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
637 // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1).
638 // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1.
639
640 if ((line_end - p < 4) || !LowerCaseEqualsASCII(p, p + 4, "http")) {
641 DVLOG(1) << "missing status line";
642 return HttpVersion();
643 }
644
645 p += 4;
646
647 if (p >= line_end || *p != '/') {
648 DVLOG(1) << "missing version";
649 return HttpVersion();
650 }
651
652 std::string::const_iterator dot = std::find(p, line_end, '.');
653 if (dot == line_end) {
654 DVLOG(1) << "malformed version";
655 return HttpVersion();
656 }
657
658 ++p; // from / to first digit.
659 ++dot; // from . to second digit.
660
661 if (!(*p >= '0' && *p <= '9' && *dot >= '0' && *dot <= '9')) {
662 DVLOG(1) << "malformed version number";
663 return HttpVersion();
664 }
665
666 uint16 major = *p - '0';
667 uint16 minor = *dot - '0';
668
669 return HttpVersion(major, minor);
670 }
671
672 // Note: this implementation implicitly assumes that line_end points at a valid
673 // sentinel character (such as '\0').
630 void HttpResponseHeaders::ParseStatusLine( 674 void HttpResponseHeaders::ParseStatusLine(
631 std::string::const_iterator line_begin, 675 std::string::const_iterator line_begin,
632 std::string::const_iterator line_end, 676 std::string::const_iterator line_end,
633 bool has_headers) { 677 bool has_headers) {
634 // Extract the version number 678 // Extract the version number
635 std::string::const_iterator first_space = 679 parsed_http_version_ = ParseVersion(line_begin, line_end);
636 std::find(line_begin, line_end, ' ');
637 std::string version(line_begin, first_space);
638 bool success = HttpUtil::ParseVersion(version, &parsed_http_version_);
639 680
640 // Clamp the version number to one of: {0.9, 1.0, 1.1} 681 // Clamp the version number to one of: {0.9, 1.0, 1.1}
641 if (success && parsed_http_version_ == HttpVersion(0, 9) && !has_headers) { 682 if (parsed_http_version_ == HttpVersion(0, 9) && !has_headers) {
642 http_version_ = HttpVersion(0, 9); 683 http_version_ = HttpVersion(0, 9);
643 raw_headers_ = "HTTP/0.9"; 684 raw_headers_ = "HTTP/0.9";
644 } else if (success && parsed_http_version_ >= HttpVersion(1, 1)) { 685 } else if (parsed_http_version_ >= HttpVersion(1, 1)) {
645 http_version_ = HttpVersion(1, 1); 686 http_version_ = HttpVersion(1, 1);
646 raw_headers_ = "HTTP/1.1"; 687 raw_headers_ = "HTTP/1.1";
647 } else { 688 } else {
648 // Treat everything else like HTTP 1.0 689 // Treat everything else like HTTP 1.0
649 http_version_ = HttpVersion(1, 0); 690 http_version_ = HttpVersion(1, 0);
650 raw_headers_ = "HTTP/1.0"; 691 raw_headers_ = "HTTP/1.0";
651 } 692 }
652 if (parsed_http_version_ != http_version_) { 693 if (parsed_http_version_ != http_version_) {
653 DVLOG(1) << "assuming HTTP/" << http_version_.major_value() << "." 694 DVLOG(1) << "assuming HTTP/" << http_version_.major_value() << "."
654 << http_version_.minor_value(); 695 << http_version_.minor_value();
655 } 696 }
656 697
657 // TODO(eroman): this doesn't make sense if ParseVersion failed. 698 // TODO(eroman): this doesn't make sense if ParseVersion failed.
658 std::string::const_iterator p = first_space; 699 std::string::const_iterator p = std::find(line_begin, line_end, ' ');
659 700
660 if (p == line_end) { 701 if (p == line_end) {
661 DVLOG(1) << "missing response status; assuming 200 OK"; 702 DVLOG(1) << "missing response status; assuming 200 OK";
662 raw_headers_.append(" 200 OK"); 703 raw_headers_.append(" 200 OK");
663 response_code_ = 200; 704 response_code_ = 200;
664 return; 705 return;
665 } 706 }
666 707
667 // Skip whitespace. 708 // Skip whitespace.
668 while (*p == ' ') 709 while (*p == ' ')
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 // should not generate representation metadata other than Cache-Control, 1497 // should not generate representation metadata other than Cache-Control,
1457 // Content-Location, Date, ETag, Expires, and Vary. 1498 // Content-Location, Date, ETag, Expires, and Vary.
1458 return ProxyService::MISSING_VIA_HEADER; 1499 return ProxyService::MISSING_VIA_HEADER;
1459 } 1500 }
1460 // There is no bypass event. 1501 // There is no bypass event.
1461 return ProxyService::BYPASS_EVENT_TYPE_MAX; 1502 return ProxyService::BYPASS_EVENT_TYPE_MAX;
1462 } 1503 }
1463 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) 1504 #endif // defined(SPDY_PROXY_AUTH_ORIGIN)
1464 1505
1465 } // namespace net 1506 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698