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

Side by Side Diff: net/http/partial_data.cc

Issue 339088: Http cache: Always preserve extra headers when dealing with... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/partial_data.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/partial_data.h" 5 #include "net/http/partial_data.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/disk_cache/disk_cache.h" 10 #include "net/disk_cache/disk_cache.h"
11 #include "net/http/http_response_headers.h" 11 #include "net/http/http_response_headers.h"
12 #include "net/http/http_util.h" 12 #include "net/http/http_util.h"
13 13
14 namespace { 14 namespace {
15 15
16 // The headers that we have to process. 16 // The headers that we have to process.
17 const char kLengthHeader[] = "Content-Length"; 17 const char kLengthHeader[] = "Content-Length";
18 const char kRangeHeader[] = "Content-Range"; 18 const char kRangeHeader[] = "Content-Range";
19 const int kDataStream = 1; 19 const int kDataStream = 1;
20 20
21 } 21 }
22 22
23 namespace net { 23 namespace net {
24 24
25 bool PartialData::Init(const std::string& headers, 25 bool PartialData::Init(const std::string& headers) {
26 const std::string& new_headers) {
27 std::vector<HttpByteRange> ranges; 26 std::vector<HttpByteRange> ranges;
28 if (!HttpUtil::ParseRanges(headers, &ranges) || ranges.size() != 1) 27 if (!HttpUtil::ParseRanges(headers, &ranges) || ranges.size() != 1)
29 return false; 28 return false;
30 29
31 // We can handle this range request. 30 // We can handle this range request.
32 byte_range_ = ranges[0]; 31 byte_range_ = ranges[0];
33 if (!byte_range_.IsValid()) 32 if (!byte_range_.IsValid())
34 return false; 33 return false;
35 34
36 extra_headers_ = new_headers;
37 resource_size_ = 0; 35 resource_size_ = 0;
38
39 current_range_start_ = byte_range_.first_byte_position(); 36 current_range_start_ = byte_range_.first_byte_position();
40 return true; 37 return true;
41 } 38 }
42 39
40 void PartialData::SetHeaders(const std::string& headers) {
41 DCHECK(extra_headers_.empty());
42 extra_headers_ = headers;
43 }
44
43 void PartialData::RestoreHeaders(std::string* headers) const { 45 void PartialData::RestoreHeaders(std::string* headers) const {
44 DCHECK(current_range_start_ >= 0 || byte_range_.IsSuffixByteRange()); 46 DCHECK(current_range_start_ >= 0 || byte_range_.IsSuffixByteRange());
45 int64 end = byte_range_.IsSuffixByteRange() ? 47 int64 end = byte_range_.IsSuffixByteRange() ?
46 byte_range_.suffix_length() : byte_range_.last_byte_position(); 48 byte_range_.suffix_length() : byte_range_.last_byte_position();
47 49
48 AddRangeHeader(current_range_start_, end, headers); 50 AddRangeHeader(current_range_start_, end, headers);
49 } 51 }
50 52
51 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry, 53 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry,
52 std::string* headers) { 54 std::string* headers) {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 if (start >= 0) 312 if (start >= 0)
311 my_start = Int64ToString(start); 313 my_start = Int64ToString(start);
312 if (end >= 0) 314 if (end >= 0)
313 my_end = Int64ToString(end); 315 my_end = Int64ToString(end);
314 316
315 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), 317 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(),
316 my_end.c_str())); 318 my_end.c_str()));
317 } 319 }
318 320
319 } // namespace net 321 } // namespace net
OLDNEW
« no previous file with comments | « net/http/partial_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698