Chromium Code Reviews| 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 HttpUtil::UpdateResponseHeadersWithRange( | |
| 387 byte_range_, resource_size_, !sparse_entry_, headers); | |
| 388 return; | |
| 389 } | |
| 390 | |
| 385 headers->RemoveHeader(kLengthHeader); | 391 headers->RemoveHeader(kLengthHeader); |
| 386 headers->RemoveHeader(kRangeHeader); | 392 headers->RemoveHeader(kRangeHeader); |
| 387 | 393 |
| 388 int64 range_len, start, end; | 394 // success==false cases. |
|
rvargas (doing something else)
2014/03/05 19:47:33
nit: remove comment
kinuko
2014/03/06 04:11:29
Done.
| |
| 389 if (byte_range_.IsValid()) { | 395 if (byte_range_.IsValid()) { |
| 390 if (success) { | 396 headers->ReplaceStatusLine("HTTP/1.1 416 Requested Range Not Satisfiable"); |
| 391 if (!sparse_entry_) | 397 headers->AddHeader(base::StringPrintf("%s: bytes 0-0/%" PRId64, |
| 392 headers->ReplaceStatusLine("HTTP/1.1 206 Partial Content"); | 398 kRangeHeader, resource_size_)); |
| 393 | 399 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 { | 400 } else { |
| 411 // TODO(rvargas): Is it safe to change the protocol version? | 401 // TODO(rvargas): Is it safe to change the protocol version? |
| 412 headers->ReplaceStatusLine("HTTP/1.1 200 OK"); | 402 headers->ReplaceStatusLine("HTTP/1.1 200 OK"); |
| 413 DCHECK_NE(resource_size_, 0); | 403 DCHECK_NE(resource_size_, 0); |
| 414 range_len = resource_size_; | 404 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, |
| 405 resource_size_)); | |
| 415 } | 406 } |
| 416 | |
| 417 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, | |
| 418 range_len)); | |
| 419 } | 407 } |
| 420 | 408 |
| 421 void PartialData::FixContentLength(HttpResponseHeaders* headers) { | 409 void PartialData::FixContentLength(HttpResponseHeaders* headers) { |
| 422 headers->RemoveHeader(kLengthHeader); | 410 headers->RemoveHeader(kLengthHeader); |
| 423 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, | 411 headers->AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, |
| 424 resource_size_)); | 412 resource_size_)); |
| 425 } | 413 } |
| 426 | 414 |
| 427 int PartialData::CacheRead( | 415 int PartialData::CacheRead( |
| 428 disk_cache::Entry* entry, IOBuffer* data, int data_len, | 416 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; | 481 cached_min_len_ = result; |
| 494 if (result >= 0) | 482 if (result >= 0) |
| 495 result = 1; // Return success, go ahead and validate the entry. | 483 result = 1; // Return success, go ahead and validate the entry. |
| 496 | 484 |
| 497 CompletionCallback cb = callback_; | 485 CompletionCallback cb = callback_; |
| 498 callback_.Reset(); | 486 callback_.Reset(); |
| 499 cb.Run(result); | 487 cb.Run(result); |
| 500 } | 488 } |
| 501 | 489 |
| 502 } // namespace net | 490 } // namespace net |
| OLD | NEW |