OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 Time* result) const { | 917 Time* result) const { |
918 std::string value; | 918 std::string value; |
919 if (!EnumerateHeader(NULL, name, &value)) | 919 if (!EnumerateHeader(NULL, name, &value)) |
920 return false; | 920 return false; |
921 | 921 |
922 std::wstring value_wide(value.begin(), value.end()); // inflate ascii | 922 std::wstring value_wide(value.begin(), value.end()); // inflate ascii |
923 return Time::FromString(value_wide.c_str(), result); | 923 return Time::FromString(value_wide.c_str(), result); |
924 } | 924 } |
925 | 925 |
926 bool HttpResponseHeaders::IsKeepAlive() const { | 926 bool HttpResponseHeaders::IsKeepAlive() const { |
927 const char kPrefix[] = "HTTP/1.0"; | 927 if (http_version_ < HttpVersion(1, 0)) |
928 const size_t kPrefixLen = arraysize(kPrefix) - 1; | |
929 if (raw_headers_.size() < kPrefixLen) // Lacking a status line? | |
930 return false; | 928 return false; |
931 | 929 |
932 // NOTE: It is perhaps risky to assume that a Proxy-Connection header is | 930 // NOTE: It is perhaps risky to assume that a Proxy-Connection header is |
933 // meaningful when we don't know that this response was from a proxy, but | 931 // meaningful when we don't know that this response was from a proxy, but |
934 // Mozilla also does this, so we'll do the same. | 932 // Mozilla also does this, so we'll do the same. |
935 std::string connection_val; | 933 std::string connection_val; |
936 void* iter = NULL; | 934 if (!EnumerateHeader(NULL, "connection", &connection_val)) |
937 if (!EnumerateHeader(&iter, "connection", &connection_val)) | 935 EnumerateHeader(NULL, "proxy-connection", &connection_val); |
938 EnumerateHeader(&iter, "proxy-connection", &connection_val); | |
939 | 936 |
940 bool keep_alive; | 937 bool keep_alive; |
941 | 938 |
942 if (std::equal(raw_headers_.begin(), | 939 if (http_version_ == HttpVersion(1, 0)) { |
943 raw_headers_.begin() + kPrefixLen, kPrefix)) { | |
944 // HTTP/1.0 responses default to NOT keep-alive | 940 // HTTP/1.0 responses default to NOT keep-alive |
945 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive"); | 941 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive"); |
946 } else { | 942 } else { |
947 // HTTP/1.1 responses default to keep-alive | 943 // HTTP/1.1 responses default to keep-alive |
948 keep_alive = !LowerCaseEqualsASCII(connection_val, "close"); | 944 keep_alive = !LowerCaseEqualsASCII(connection_val, "close"); |
949 } | 945 } |
950 | 946 |
951 return keep_alive; | 947 return keep_alive; |
952 } | 948 } |
953 | 949 |
(...skipping 14 matching lines...) Expand all Loading... |
968 int64 result; | 964 int64 result; |
969 bool ok = StringToInt64(content_length_val, &result); | 965 bool ok = StringToInt64(content_length_val, &result); |
970 if (!ok || result < 0) | 966 if (!ok || result < 0) |
971 return -1; | 967 return -1; |
972 | 968 |
973 return result; | 969 return result; |
974 } | 970 } |
975 | 971 |
976 } // namespace net | 972 } // namespace net |
977 | 973 |
OLD | NEW |