Chromium Code Reviews| 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..d22ff75c2dbe9309d741a31e0743890d04839791 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()); |
| + } else if (HasLastBytePosition()) { |
|
scherkus (not reviewing)
2013/11/25 22:53:10
nit: you don't really need these elses
tommycli
2013/11/25 23:05:58
Done.
|
| + DCHECK(HasFirstBytePosition()); |
| + return base::StringPrintf("bytes=%" PRId64 "-%" PRId64, |
| + first_byte_position(), last_byte_position()); |
| + } else { |
| + DCHECK(HasFirstBytePosition()); |
| + return base::StringPrintf("bytes=%" PRId64 "-", first_byte_position()); |
| + } |
| +} |
| + |
| bool HttpByteRange::ComputeBounds(int64 size) { |
| if (size < 0) |
| return false; |