OLD | NEW |
---|---|
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/format_macros.h" | |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
9 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
10 #include "net/disk_cache/disk_cache.h" | 11 #include "net/disk_cache/disk_cache.h" |
11 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
12 #include "net/http/http_util.h" | 13 #include "net/http/http_util.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // The headers that we have to process. | 17 // The headers that we have to process. |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 headers->RemoveHeader(kLengthHeader); | 231 headers->RemoveHeader(kLengthHeader); |
231 headers->RemoveHeader(kRangeHeader); | 232 headers->RemoveHeader(kRangeHeader); |
232 | 233 |
233 int64 range_len; | 234 int64 range_len; |
234 if (byte_range_.IsValid()) { | 235 if (byte_range_.IsValid()) { |
235 if (!sparse_entry_) | 236 if (!sparse_entry_) |
236 headers->ReplaceStatusLine("HTTP/1.1 206 Partial Content"); | 237 headers->ReplaceStatusLine("HTTP/1.1 206 Partial Content"); |
237 | 238 |
238 DCHECK(byte_range_.HasFirstBytePosition()); | 239 DCHECK(byte_range_.HasFirstBytePosition()); |
239 DCHECK(byte_range_.HasLastBytePosition()); | 240 DCHECK(byte_range_.HasLastBytePosition()); |
240 headers->AddHeader(StringPrintf("%s: bytes %lld-%lld/%lld", kRangeHeader, | 241 headers->AddHeader(StringPrintf("%s: bytes %"PRId64"-%"PRId64"/%"PRId64, |
Mark Mentovai
2009/11/18 20:55:27
More spaces.
| |
242 kRangeHeader, | |
241 byte_range_.first_byte_position(), | 243 byte_range_.first_byte_position(), |
242 byte_range_.last_byte_position(), | 244 byte_range_.last_byte_position(), |
243 resource_size_)); | 245 resource_size_)); |
244 range_len = byte_range_.last_byte_position() - | 246 range_len = byte_range_.last_byte_position() - |
245 byte_range_.first_byte_position() + 1; | 247 byte_range_.first_byte_position() + 1; |
246 } else { | 248 } else { |
247 // TODO(rvargas): Is it safe to change the protocol version? | 249 // TODO(rvargas): Is it safe to change the protocol version? |
248 headers->ReplaceStatusLine("HTTP/1.1 200 OK"); | 250 headers->ReplaceStatusLine("HTTP/1.1 200 OK"); |
249 DCHECK_NE(resource_size_, 0); | 251 DCHECK_NE(resource_size_, 0); |
250 range_len = resource_size_; | 252 range_len = resource_size_; |
251 } | 253 } |
252 | 254 |
253 headers->AddHeader(StringPrintf("%s: %lld", kLengthHeader, range_len)); | 255 headers->AddHeader(StringPrintf("%s: %" PRId64, kLengthHeader, range_len)); |
254 } | 256 } |
255 | 257 |
256 void PartialData::FixContentLength(HttpResponseHeaders* headers) { | 258 void PartialData::FixContentLength(HttpResponseHeaders* headers) { |
257 headers->RemoveHeader(kLengthHeader); | 259 headers->RemoveHeader(kLengthHeader); |
258 headers->AddHeader(StringPrintf("%s: %lld", kLengthHeader, resource_size_)); | 260 headers->AddHeader(StringPrintf("%s: %"PRId64, kLengthHeader, resource_size_)) ; |
Mark Mentovai
2009/11/18 20:55:27
Even more spaces.
Busted 80 columns, too.
| |
259 } | 261 } |
260 | 262 |
261 int PartialData::CacheRead(disk_cache::Entry* entry, IOBuffer* data, | 263 int PartialData::CacheRead(disk_cache::Entry* entry, IOBuffer* data, |
262 int data_len, CompletionCallback* callback) { | 264 int data_len, CompletionCallback* callback) { |
263 int read_len = std::min(data_len, cached_min_len_); | 265 int read_len = std::min(data_len, cached_min_len_); |
264 if (!read_len) | 266 if (!read_len) |
265 return 0; | 267 return 0; |
266 | 268 |
267 int rv = 0; | 269 int rv = 0; |
268 if (sparse_entry_) { | 270 if (sparse_entry_) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 if (start >= 0) | 314 if (start >= 0) |
313 my_start = Int64ToString(start); | 315 my_start = Int64ToString(start); |
314 if (end >= 0) | 316 if (end >= 0) |
315 my_end = Int64ToString(end); | 317 my_end = Int64ToString(end); |
316 | 318 |
317 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), | 319 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), |
318 my_end.c_str())); | 320 my_end.c_str())); |
319 } | 321 } |
320 | 322 |
321 } // namespace net | 323 } // namespace net |
OLD | NEW |