| Index: net/http/http_byte_range.cc
|
| diff --git a/net/http/http_byte_range.cc b/net/http/http_byte_range.cc
|
| index 60683c5584f5578dd0c4e76ce41f4c12341cdacc..b43cb2e8008608c025ceb94355cb28d06b818ab7 100644
|
| --- a/net/http/http_byte_range.cc
|
| +++ b/net/http/http_byte_range.cc
|
| @@ -4,6 +4,9 @@
|
|
|
| #include <algorithm>
|
|
|
| +#include "base/format_macros.h"
|
| +#include "base/logging.h"
|
| +#include "base/strings/stringprintf.h"
|
| #include "net/http/http_byte_range.h"
|
|
|
| namespace {
|
| @@ -21,6 +24,29 @@ HttpByteRange::HttpByteRange()
|
| has_computed_bounds_(false) {
|
| }
|
|
|
| +// static
|
| +HttpByteRange HttpByteRange::Bounded(int64 first_byte_position,
|
| + int64 last_byte_position) {
|
| + HttpByteRange range;
|
| + range.set_first_byte_position(first_byte_position);
|
| + range.set_last_byte_position(last_byte_position);
|
| + return range;
|
| +}
|
| +
|
| +// static
|
| +HttpByteRange HttpByteRange::RightUnbounded(int64 first_byte_position) {
|
| + HttpByteRange range;
|
| + range.set_first_byte_position(first_byte_position);
|
| + return range;
|
| +}
|
| +
|
| +// static
|
| +HttpByteRange HttpByteRange::Suffix(int64 suffix_length) {
|
| + HttpByteRange range;
|
| + range.set_suffix_length(suffix_length);
|
| + return range;
|
| +}
|
| +
|
| bool HttpByteRange::IsSuffixByteRange() const {
|
| return suffix_length_ != kPositionNotSpecified;
|
| }
|
| @@ -41,6 +67,21 @@ bool HttpByteRange::IsValid() const {
|
| last_byte_position_ >= first_byte_position_));
|
| }
|
|
|
| +std::string HttpByteRange::GetHeaderValue() const {
|
| + DCHECK(IsValid());
|
| +
|
| + if (IsSuffixByteRange())
|
| + return base::StringPrintf("bytes=-%" PRId64, suffix_length());
|
| +
|
| + DCHECK(HasFirstBytePosition());
|
| +
|
| + if (!HasLastBytePosition())
|
| + return base::StringPrintf("bytes=%" PRId64 "-", first_byte_position());
|
| +
|
| + return base::StringPrintf("bytes=%" PRId64 "-%" PRId64,
|
| + first_byte_position(), last_byte_position());
|
| +}
|
| +
|
| bool HttpByteRange::ComputeBounds(int64 size) {
|
| if (size < 0)
|
| return false;
|
|
|