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..0a97eae76b3fdacc81dde747ce6687840f0b8acf 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::PrintHeader() const { |
+ DCHECK(IsValid()); |
+ |
+ if (IsSuffixByteRange()) { |
+ return base::StringPrintf("bytes=-%" PRId64, suffix_length()); |
+ } else if (HasLastBytePosition()) { |
+ 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; |