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
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_url_request_job.h"
7 #include "net/http/http_request_headers.h"
8 #include "net/http/http_response_headers.h"
9 #include "net/http/http_response_info.h"
10 #include "net/http/http_util.h"
14 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob(
15 net::URLRequest
* request
,
16 net::NetworkDelegate
* network_delegate
)
17 : net::URLRequestJob(request
, network_delegate
),
21 void ServiceWorkerURLRequestJob::Start() {
25 void ServiceWorkerURLRequestJob::Kill() {
26 net::URLRequestJob::Kill();
27 weak_factory_
.InvalidateWeakPtrs();
30 net::LoadState
ServiceWorkerURLRequestJob::GetLoadState() const {
31 // TODO(kinuko): refine this for better debug.
32 return net::URLRequestJob::GetLoadState();
35 bool ServiceWorkerURLRequestJob::GetCharset(std::string
* charset
) {
38 return http_info()->headers
->GetCharset(charset
);
41 bool ServiceWorkerURLRequestJob::GetMimeType(std::string
* mime_type
) const {
44 return http_info()->headers
->GetMimeType(mime_type
);
47 void ServiceWorkerURLRequestJob::GetResponseInfo(net::HttpResponseInfo
* info
) {
53 int ServiceWorkerURLRequestJob::GetResponseCode() const {
56 return http_info()->headers
->response_code();
59 void ServiceWorkerURLRequestJob::SetExtraRequestHeaders(
60 const net::HttpRequestHeaders
& headers
) {
61 std::string range_header
;
62 std::vector
<net::HttpByteRange
> ranges
;
63 if (!headers
.GetHeader(net::HttpRequestHeaders::kRange
, &range_header
) ||
64 !net::HttpUtil::ParseRangeHeader(range_header
, &ranges
)) {
68 // We don't support multiple range requests in one single URL request.
69 if (ranges
.size() == 1U)
70 byte_range_
= ranges
[0];
73 bool ServiceWorkerURLRequestJob::ReadRawData(
74 net::IOBuffer
* buf
, int buf_size
, int *bytes_read
) {
80 const net::HttpResponseInfo
* ServiceWorkerURLRequestJob::http_info() const {
81 if (!http_response_info_
)
83 if (range_response_info_
)
84 return range_response_info_
.get();
85 return http_response_info_
.get();
88 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() {
91 } // namespace content