summaryrefslogtreecommitdiffstats
path: root/chromium/net/http/http_response_headers.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/http/http_response_headers.cc')
-rw-r--r--chromium/net/http/http_response_headers.cc118
1 files changed, 45 insertions, 73 deletions
diff --git a/chromium/net/http/http_response_headers.cc b/chromium/net/http/http_response_headers.cc
index 289facd4f9e..b7ef98a5980 100644
--- a/chromium/net/http/http_response_headers.cc
+++ b/chromium/net/http/http_response_headers.cc
@@ -11,6 +11,7 @@
#include <algorithm>
+#include "base/format_macros.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/pickle.h"
@@ -21,6 +22,8 @@
#include "base/time/time.h"
#include "base/values.h"
#include "net/base/escape.h"
+#include "net/http/http_byte_range.h"
+#include "net/http/http_log_util.h"
#include "net/http/http_util.h"
using base::StringPiece;
@@ -113,16 +116,10 @@ void CheckDoesNotHaveEmbededNulls(const std::string& str) {
CHECK(str.find('\0') == std::string::npos);
}
-bool ShouldShowHttpHeaderValue(const std::string& header_name) {
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
- if (header_name == "Proxy-Authenticate")
- return false;
-#endif
- return true;
-}
-
} // namespace
+const char HttpResponseHeaders::kContentRange[] = "Content-Range";
+
struct HttpResponseHeaders::ParsedHeader {
// A header "continuation" contains only a subsequent value for the
// preceding header. (Header values are comma separated.)
@@ -372,6 +369,32 @@ void HttpResponseHeaders::ReplaceStatusLine(const std::string& new_status) {
MergeWithHeaders(new_raw_headers, empty_to_remove);
}
+void HttpResponseHeaders::UpdateWithNewRange(
+ const HttpByteRange& byte_range,
+ int64 resource_size,
+ bool replace_status_line) {
+ DCHECK(byte_range.IsValid());
+ DCHECK(byte_range.HasFirstBytePosition());
+ DCHECK(byte_range.HasLastBytePosition());
+
+ const char kLengthHeader[] = "Content-Length";
+ const char kRangeHeader[] = "Content-Range";
+
+ RemoveHeader(kLengthHeader);
+ RemoveHeader(kRangeHeader);
+
+ int64 start = byte_range.first_byte_position();
+ int64 end = byte_range.last_byte_position();
+ int64 range_len = end - start + 1;
+
+ if (replace_status_line)
+ ReplaceStatusLine("HTTP/1.1 206 Partial Content");
+
+ AddHeader(base::StringPrintf("%s: bytes %" PRId64 "-%" PRId64 "/%" PRId64,
+ kRangeHeader, start, end, resource_size));
+ AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, range_len));
+}
+
void HttpResponseHeaders::Parse(const std::string& raw_input) {
raw_headers_.reserve(raw_input.size());
@@ -827,7 +850,7 @@ void HttpResponseHeaders::AddChallengeHeaders(HeaderSet* result) {
}
void HttpResponseHeaders::AddHopContentRangeHeaders(HeaderSet* result) {
- result->insert("content-range");
+ result->insert(kContentRange);
}
void HttpResponseHeaders::AddSecurityStateHeaders(HeaderSet* result) {
@@ -894,7 +917,8 @@ bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) {
return (response_code == 301 ||
response_code == 302 ||
response_code == 303 ||
- response_code == 307);
+ response_code == 307 ||
+ response_code == 308);
}
// From RFC 2616 section 13.2.4:
@@ -993,6 +1017,9 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime(
// time, if, based solely on the origin server's Expires or max-age value,
// the cached response is stale.)
//
+ // https://datatracker.ietf.org/doc/draft-reschke-http-status-308/ is an
+ // experimental RFC that adds 308 permanent redirect as well, for which "any
+ // future references ... SHOULD use one of the returned URIs."
if ((response_code_ == 200 || response_code_ == 203 ||
response_code_ == 206) &&
!HasHeaderValue("cache-control", "must-revalidate")) {
@@ -1006,8 +1033,10 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime(
}
// These responses are implicitly fresh (unless otherwise overruled):
- if (response_code_ == 300 || response_code_ == 301 || response_code_ == 410)
- return TimeDelta::FromMicroseconds(kint64max);
+ if (response_code_ == 300 || response_code_ == 301 || response_code_ == 308 ||
+ response_code_ == 410) {
+ return TimeDelta::Max();
+ }
return TimeDelta(); // not fresh
}
@@ -1207,7 +1236,7 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position,
void* iter = NULL;
std::string content_range_spec;
*first_byte_position = *last_byte_position = *instance_length = -1;
- if (!EnumerateHeader(&iter, "content-range", &content_range_spec))
+ if (!EnumerateHeader(&iter, kContentRange, &content_range_spec))
return false;
// If the header value is empty, we have an invalid header.
@@ -1308,7 +1337,7 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position,
}
base::Value* HttpResponseHeaders::NetLogCallback(
- NetLog::LogLevel /* log_level */) const {
+ NetLog::LogLevel log_level) const {
base::DictionaryValue* dict = new base::DictionaryValue();
base::ListValue* headers = new base::ListValue();
headers->Append(new base::StringValue(GetStatusLine()));
@@ -1316,12 +1345,10 @@ base::Value* HttpResponseHeaders::NetLogCallback(
std::string name;
std::string value;
while (EnumerateHeaderLines(&iterator, &name, &value)) {
+ std::string log_value = ElideHeaderValueForNetLog(log_level, name, value);
headers->Append(
new base::StringValue(
- base::StringPrintf("%s: %s",
- name.c_str(),
- (ShouldShowHttpHeaderValue(name) ?
- value.c_str() : "[elided]"))));
+ base::StringPrintf("%s: %s", name.c_str(), log_value.c_str())));
}
dict->Set("headers", headers);
return dict;
@@ -1364,59 +1391,4 @@ bool HttpResponseHeaders::IsChunkEncoded() const {
HasHeaderValue("Transfer-Encoding", "chunked");
}
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
-bool HttpResponseHeaders::GetChromeProxyBypassDuration(
- const std::string& action_prefix,
- base::TimeDelta* duration) const {
- void* iter = NULL;
- std::string value;
- std::string name = "chrome-proxy";
-
- while (EnumerateHeader(&iter, name, &value)) {
- if (value.size() > action_prefix.size()) {
- if (LowerCaseEqualsASCII(value.begin(),
- value.begin() + action_prefix.size(),
- action_prefix.c_str())) {
- int64 seconds;
- if (!base::StringToInt64(
- StringPiece(value.begin() + action_prefix.size(), value.end()),
- &seconds) || seconds < 0) {
- continue; // In case there is a well formed instruction.
- }
- *duration = TimeDelta::FromSeconds(seconds);
- return true;
- }
- }
- }
- return false;
-}
-
-bool HttpResponseHeaders::GetChromeProxyInfo(
- ChromeProxyInfo* proxy_info) const {
- DCHECK(proxy_info);
- proxy_info->bypass_all = false;
- proxy_info->bypass_duration = base::TimeDelta();
-
- // Support header of the form Chrome-Proxy: bypass|block=<duration>, where
- // <duration> is the number of seconds to wait before retrying
- // the proxy. If the duration is 0, then the default proxy retry delay
- // (specified in |ProxyList::UpdateRetryInfoOnFallback|) will be used.
- // 'bypass' instructs Chrome to bypass the currently connected Chrome proxy,
- // whereas 'block' instructs Chrome to bypass all available Chrome proxies.
-
- // 'block' takes precedence over 'bypass', so look for it first.
- // TODO(bengr): Reduce checks for 'block' and 'bypass' to a single loop.
- if (GetChromeProxyBypassDuration("block=", &proxy_info->bypass_duration)) {
- proxy_info->bypass_all = true;
- return true;
- }
-
- // Next, look for 'bypass'.
- if (GetChromeProxyBypassDuration("bypass=", &proxy_info->bypass_duration))
- return true;
-
- return false;
-}
-#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
-
} // namespace net