Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Unified Diff: net/http/http_byte_range.cc

Issue 78343004: Net: Standardize HttpByteRange printing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_byte_range.h ('k') | net/http/http_byte_range_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « net/http/http_byte_range.h ('k') | net/http/http_byte_range_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698