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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
892 // static | 892 // static |
893 bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { | 893 bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { |
894 // Users probably want to see 300 (multiple choice) pages, so we don't count | 894 // Users probably want to see 300 (multiple choice) pages, so we don't count |
895 // them as redirects that need to be followed. | 895 // them as redirects that need to be followed. |
896 return (response_code == 301 || | 896 return (response_code == 301 || |
897 response_code == 302 || | 897 response_code == 302 || |
898 response_code == 303 || | 898 response_code == 303 || |
899 response_code == 307); | 899 response_code == 307); |
900 } | 900 } |
901 | 901 |
902 void HttpResponseHeaders::SetSafeRedirect(GURL new_url) { | |
903 DCHECK(new_url.is_valid()); | |
904 // Replace the status line and Location header | |
905 std::string new_raw_headers("HTTP/1.1 307 Temporary Redirect"); | |
906 new_raw_headers.push_back('\0'); | |
907 new_raw_headers.append("Location: " + new_url.spec()); | |
908 new_raw_headers.push_back('\0'); | |
909 | |
910 HeaderSet to_remove; | |
911 to_remove.insert("location"); | |
912 | |
913 MergeWithHeaders(new_raw_headers, to_remove); | |
914 | |
915 allowed_unsafe_redirect_url_ = new_url; | |
916 } | |
917 | |
918 bool HttpResponseHeaders::IsSafeRedirect(const GURL& location) const { | |
919 if (allowed_unsafe_redirect_url_.is_valid()) { | |
920 GURL::Replacements replacements; | |
921 replacements.ClearRef(); | |
mmenke
2014/03/20 16:13:32
Hrm... Is this needed?
robwu
2014/03/20 16:21:11
Yes, URLRequestJob::NotifyHeadersComplete() copies
mmenke
2014/03/20 16:40:28
Thanks for the pointer! Then we should clear the
robwu
2014/03/20 17:28:14
The ref is already cleared on both URLs.
| |
922 return location.ReplaceComponents(replacements) == | |
923 allowed_unsafe_redirect_url_.ReplaceComponents(replacements); | |
924 } | |
925 return false; | |
926 } | |
927 bool HttpResponseHeaders::HasSafeRedirect() const { | |
928 return allowed_unsafe_redirect_url_.is_valid(); | |
929 } | |
930 | |
902 // From RFC 2616 section 13.2.4: | 931 // From RFC 2616 section 13.2.4: |
903 // | 932 // |
904 // The calculation to determine if a response has expired is quite simple: | 933 // The calculation to determine if a response has expired is quite simple: |
905 // | 934 // |
906 // response_is_fresh = (freshness_lifetime > current_age) | 935 // response_is_fresh = (freshness_lifetime > current_age) |
907 // | 936 // |
908 // Of course, there are other factors that can force a response to always be | 937 // Of course, there are other factors that can force a response to always be |
909 // validated or re-fetched. | 938 // validated or re-fetched. |
910 // | 939 // |
911 bool HttpResponseHeaders::RequiresValidation(const Time& request_time, | 940 bool HttpResponseHeaders::RequiresValidation(const Time& request_time, |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1440 iter = NULL; | 1469 iter = NULL; |
1441 while (EnumerateHeader(&iter, "via", &value)) | 1470 while (EnumerateHeader(&iter, "via", &value)) |
1442 if (value == kDeprecatedChromeProxyViaValue) | 1471 if (value == kDeprecatedChromeProxyViaValue) |
1443 return true; | 1472 return true; |
1444 | 1473 |
1445 return false; | 1474 return false; |
1446 } | 1475 } |
1447 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 1476 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
1448 | 1477 |
1449 } // namespace net | 1478 } // namespace net |
OLD | NEW |