OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_url_request_job.h" | 5 #include "content/browser/service_worker/service_worker_url_request_job.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 CreateResponseHeader( | 409 CreateResponseHeader( |
410 response.status_code, response.status_text, response.headers); | 410 response.status_code, response.status_text, response.headers); |
411 load_timing_info_.receive_headers_end = base::TimeTicks::Now(); | 411 load_timing_info_.receive_headers_end = base::TimeTicks::Now(); |
412 if (!blob_request_) | 412 if (!blob_request_) |
413 CommitResponseHeader(); | 413 CommitResponseHeader(); |
414 } | 414 } |
415 | 415 |
416 void ServiceWorkerURLRequestJob::CreateResponseHeader( | 416 void ServiceWorkerURLRequestJob::CreateResponseHeader( |
417 int status_code, | 417 int status_code, |
418 const std::string& status_text, | 418 const std::string& status_text, |
419 const std::map<std::string, std::string>& headers) { | 419 const ServiceWorkerHeaderMap& headers) { |
420 // TODO(kinuko): If the response has an identifier to on-disk cache entry, | 420 // TODO(kinuko): If the response has an identifier to on-disk cache entry, |
421 // pull response header from the disk. | 421 // pull response header from the disk. |
422 std::string status_line( | 422 std::string status_line( |
423 base::StringPrintf("HTTP/1.1 %d %s", status_code, status_text.c_str())); | 423 base::StringPrintf("HTTP/1.1 %d %s", status_code, status_text.c_str())); |
424 status_line.push_back('\0'); | 424 status_line.push_back('\0'); |
425 http_response_headers_ = new net::HttpResponseHeaders(status_line); | 425 http_response_headers_ = new net::HttpResponseHeaders(status_line); |
426 for (std::map<std::string, std::string>::const_iterator it = headers.begin(); | 426 for (ServiceWorkerHeaderMap::const_iterator it = headers.begin(); |
427 it != headers.end(); | 427 it != headers.end(); |
428 ++it) { | 428 ++it) { |
429 std::string header; | 429 std::string header; |
430 header.reserve(it->first.size() + 2 + it->second.size()); | 430 header.reserve(it->first.size() + 2 + it->second.size()); |
431 header.append(it->first); | 431 header.append(it->first); |
432 header.append(": "); | 432 header.append(": "); |
433 header.append(it->second); | 433 header.append(it->second); |
434 http_response_headers_->AddHeader(header); | 434 http_response_headers_->AddHeader(header); |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 void ServiceWorkerURLRequestJob::CommitResponseHeader() { | 438 void ServiceWorkerURLRequestJob::CommitResponseHeader() { |
439 http_response_info_.reset(new net::HttpResponseInfo()); | 439 http_response_info_.reset(new net::HttpResponseInfo()); |
440 http_response_info_->headers.swap(http_response_headers_); | 440 http_response_info_->headers.swap(http_response_headers_); |
441 NotifyHeadersComplete(); | 441 NotifyHeadersComplete(); |
442 } | 442 } |
443 | 443 |
444 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { | 444 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { |
445 // TODO(falken): Print an error to the console of the ServiceWorker and of | 445 // TODO(falken): Print an error to the console of the ServiceWorker and of |
446 // the requesting page. | 446 // the requesting page. |
447 CreateResponseHeader(500, | 447 CreateResponseHeader( |
448 "Service Worker Response Error", | 448 500, "Service Worker Response Error", ServiceWorkerHeaderMap()); |
449 std::map<std::string, std::string>()); | |
450 CommitResponseHeader(); | 449 CommitResponseHeader(); |
451 } | 450 } |
452 | 451 |
453 } // namespace content | 452 } // namespace content |
OLD | NEW |