OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 375 } |
376 | 376 |
377 // We are making multiple requests to complete the range requested by the user. | 377 // We are making multiple requests to complete the range requested by the user. |
378 // Just assume that everything is fine and say that we are returning what was | 378 // Just assume that everything is fine and say that we are returning what was |
379 // requested. | 379 // requested. |
380 void PartialData::FixResponseHeaders(HttpResponseHeaders* headers, | 380 void PartialData::FixResponseHeaders(HttpResponseHeaders* headers, |
381 bool success) { | 381 bool success) { |
382 if (truncated_) | 382 if (truncated_) |
383 return; | 383 return; |
384 | 384 |
| 385 if (byte_range_.IsValid() && success) { |
| 386 headers->UpdateWithNewRange(byte_range_, resource_size_, !sparse_entry_); |
| 387 return; |
| 388 } |
| 389 |
385 headers->RemoveHeader(kLengthHeader); | 390 headers->RemoveHeader(kLengthHeader); |
386 headers->RemoveHeader(kRangeHeader); | 391 headers->RemoveHeader(kRangeHeader); |
387 | 392 |
388 int64 range_len, start, end; | |
389 if (byte_range_.IsValid()) { | 393 if (byte_range_.IsValid()) { |
390 if (success) { | 394 headers->ReplaceStatusLine("HTTP/1.1 416 Requested Range Not Satisfiable"); |
391 if (!sparse_entry_) | 395 headers->AddHeader(base::StringPrintf("%s: bytes 0-0/%" PRId64, |
392 headers->ReplaceStatusLine("HTTP/1.1 206 Partial Content"); | 396 kRangeHeader, resource_size_)); |
393 | 397 headers->AddHeader(base::StringPrintf("%s: 0", kLengthHeader)); |
394 DCHECK(byte_range_.HasFirstBytePosition()); | |
395 DCHECK(byte_range_.HasLastBytePosition()); | |
396 start = byte_range_.first_byte_position(); | |
397 end = byte_range_.last_byte_position(); | |
398 range_len = end - start + 1; | |
399 } else { | |
400 headers->ReplaceStatusLine( | |
401 "HTTP/1.1 416 Requested Range Not Satisfiable"); | |
402 start = 0; | |
403 end = 0; | |
404 range_len = 0; | |
405 } | |
406 | |
407 headers->AddHeader( | |
408 base::StringPrintf("%s: bytes %" PRId64 "-%" PRId64 "/%" PRId64, | |
409 kRangeHeader, start, end, resource_size_)); | |
410 } else { | 398 } else { |
411 // TODO(rvargas): Is it safe to change the protocol version? | 399 // TODO(rvargas): Is it safe to change the protocol version? |
412 headers->ReplaceStatusLine("HTTP/1.1 200 OK"); | 400 headers->ReplaceStatusLine("HTTP/1.1 200 OK"); |
413 DCHECK_NE(resource_size_, 0); | 401 DCHECK_NE(resource_size_, 0); |
414 range_len = resource_size_; | 402 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, |
| 403 resource_size_)); |
415 } | 404 } |
416 | |
417 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, | |
418 range_len)); | |
419 } | 405 } |
420 | 406 |
421 void PartialData::FixContentLength(HttpResponseHeaders* headers) { | 407 void PartialData::FixContentLength(HttpResponseHeaders* headers) { |
422 headers->RemoveHeader(kLengthHeader); | 408 headers->RemoveHeader(kLengthHeader); |
423 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, | 409 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, |
424 resource_size_)); | 410 resource_size_)); |
425 } | 411 } |
426 | 412 |
427 int PartialData::CacheRead( | 413 int PartialData::CacheRead( |
428 disk_cache::Entry* entry, IOBuffer* data, int data_len, | 414 disk_cache::Entry* entry, IOBuffer* data, int data_len, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 cached_min_len_ = result; | 479 cached_min_len_ = result; |
494 if (result >= 0) | 480 if (result >= 0) |
495 result = 1; // Return success, go ahead and validate the entry. | 481 result = 1; // Return success, go ahead and validate the entry. |
496 | 482 |
497 CompletionCallback cb = callback_; | 483 CompletionCallback cb = callback_; |
498 callback_.Reset(); | 484 callback_.Reset(); |
499 cb.Run(result); | 485 cb.Run(result); |
500 } | 486 } |
501 | 487 |
502 } // namespace net | 488 } // namespace net |
OLD | NEW |