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 "webkit/browser/appcache/appcache_url_request_job.h" | 5 #include "webkit/browser/appcache/appcache_url_request_job.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 303 |
304 void AppCacheURLRequestJob::SetupRangeResponse() { | 304 void AppCacheURLRequestJob::SetupRangeResponse() { |
305 DCHECK(is_range_request() && info_.get() && reader_.get() && | 305 DCHECK(is_range_request() && info_.get() && reader_.get() && |
306 is_delivering_appcache_response()); | 306 is_delivering_appcache_response()); |
307 int resource_size = static_cast<int>(info_->response_data_size()); | 307 int resource_size = static_cast<int>(info_->response_data_size()); |
308 if (resource_size < 0 || !range_requested_.ComputeBounds(resource_size)) { | 308 if (resource_size < 0 || !range_requested_.ComputeBounds(resource_size)) { |
309 range_requested_ = net::HttpByteRange(); | 309 range_requested_ = net::HttpByteRange(); |
310 return; | 310 return; |
311 } | 311 } |
312 | 312 |
313 DCHECK(range_requested_.HasFirstBytePosition() && | 313 DCHECK(range_requested_.IsValid()); |
314 range_requested_.HasLastBytePosition()); | |
315 int offset = static_cast<int>(range_requested_.first_byte_position()); | 314 int offset = static_cast<int>(range_requested_.first_byte_position()); |
316 int length = static_cast<int>(range_requested_.last_byte_position() - | 315 int length = static_cast<int>(range_requested_.last_byte_position() - |
317 range_requested_.first_byte_position() + 1); | 316 range_requested_.first_byte_position() + 1); |
318 | 317 |
319 // Tell the reader about the range to read. | 318 // Tell the reader about the range to read. |
320 reader_->SetReadRange(offset, length); | 319 reader_->SetReadRange(offset, length); |
321 | 320 |
322 // Make a copy of the full response headers and fix them up | 321 // Make a copy of the full response headers and fix them up |
323 // for the range we'll be returning. | 322 // for the range we'll be returning. |
324 const char kLengthHeader[] = "Content-Length"; | |
325 const char kRangeHeader[] = "Content-Range"; | |
326 const char kPartialStatusLine[] = "HTTP/1.1 206 Partial Content"; | |
327 range_response_info_.reset( | 323 range_response_info_.reset( |
328 new net::HttpResponseInfo(*info_->http_response_info())); | 324 new net::HttpResponseInfo(*info_->http_response_info())); |
329 net::HttpResponseHeaders* headers = range_response_info_->headers.get(); | 325 net::HttpResponseHeaders* headers = range_response_info_->headers.get(); |
330 headers->RemoveHeader(kLengthHeader); | 326 headers->UpdateWithNewRange( |
331 headers->RemoveHeader(kRangeHeader); | 327 range_requested_, resource_size, true /* replace status line */); |
332 headers->ReplaceStatusLine(kPartialStatusLine); | |
333 headers->AddHeader( | |
334 base::StringPrintf("%s: %d", kLengthHeader, length)); | |
335 headers->AddHeader( | |
336 base::StringPrintf("%s: bytes %d-%d/%d", | |
337 kRangeHeader, | |
338 offset, | |
339 offset + length - 1, | |
340 resource_size)); | |
341 } | 328 } |
342 | 329 |
343 void AppCacheURLRequestJob::OnReadComplete(int result) { | 330 void AppCacheURLRequestJob::OnReadComplete(int result) { |
344 DCHECK(is_delivering_appcache_response()); | 331 DCHECK(is_delivering_appcache_response()); |
345 if (result == 0) { | 332 if (result == 0) { |
346 NotifyDone(net::URLRequestStatus()); | 333 NotifyDone(net::URLRequestStatus()); |
347 } else if (result < 0) { | 334 } else if (result < 0) { |
348 if (storage_->service()->storage() == storage_) { | 335 if (storage_->service()->storage() == storage_) { |
349 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_, | 336 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_, |
350 entry_.response_id()); | 337 entry_.response_id()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 return; | 431 return; |
445 } | 432 } |
446 | 433 |
447 // If multiple ranges are requested, we play dumb and | 434 // If multiple ranges are requested, we play dumb and |
448 // return the entire response with 200 OK. | 435 // return the entire response with 200 OK. |
449 if (ranges.size() == 1U) | 436 if (ranges.size() == 1U) |
450 range_requested_ = ranges[0]; | 437 range_requested_ = ranges[0]; |
451 } | 438 } |
452 | 439 |
453 } // namespace appcache | 440 } // namespace appcache |
OLD | NEW |