Chromium Code Reviews| Index: net/http/http_util.cc |
| diff --git a/net/http/http_util.cc b/net/http/http_util.cc |
| index 77f498133bc606cf2d64e9020c25c4ac8b8e480d..e025c52a4f2a172bbc4da3e9e116d1d5d9c30e02 100644 |
| --- a/net/http/http_util.cc |
| +++ b/net/http/http_util.cc |
| @@ -10,6 +10,7 @@ |
| #include <algorithm> |
| #include "base/basictypes.h" |
| +#include "base/format_macros.h" |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_piece.h" |
| @@ -17,6 +18,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/time/time.h" |
| +#include "net/http/http_response_headers.h" |
| using std::string; |
| @@ -289,6 +291,37 @@ bool HttpUtil::ParseRangeHeader(const std::string& ranges_specifier, |
| } |
| // static |
| +bool HttpUtil::UpdateResponseHeadersWithRange( |
| + const HttpByteRange& byte_range, |
| + int64 resource_size, |
| + bool replace_status_line, |
| + HttpResponseHeaders* headers) { |
| + DCHECK(headers); |
| + if (!byte_range.IsValid()) |
|
rvargas (doing something else)
2014/03/05 19:47:33
We should probably dcheck this and return void...
kinuko
2014/03/06 04:11:29
Done.
|
| + return false; |
| + |
| + const char kLengthHeader[] = "Content-Length"; |
| + const char kRangeHeader[] = "Content-Range"; |
| + |
| + headers->RemoveHeader(kLengthHeader); |
| + headers->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) |
| + headers->ReplaceStatusLine("HTTP/1.1 206 Partial Content"); |
| + |
| + headers->AddHeader( |
| + base::StringPrintf("%s: bytes %" PRId64 "-%" PRId64 "/%" PRId64, |
| + kRangeHeader, start, end, resource_size)); |
| + headers->AddHeader( |
| + base::StringPrintf("%s: %" PRId64, kLengthHeader, range_len)); |
| + return true; |
| +} |
| + |
| +// static |
| bool HttpUtil::HasHeader(const std::string& headers, const char* name) { |
| size_t name_len = strlen(name); |
| string::const_iterator it = |