1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "third_party/blink/public/platform/web_http_load_info.h"
32
33 #include "third_party/blink/public/platform/web_http_header_visitor.h"
34 #include "third_party/blink/public/platform/web_string.h"
35 #include "third_party/blink/renderer/platform/loader/fetch/resource_load_info.h"
36
37 namespace blink {
38
Initialize()39 void WebHTTPLoadInfo::Initialize() {
40 private_ = base::AdoptRef(new ResourceLoadInfo());
41 }
42
Reset()43 void WebHTTPLoadInfo::Reset() {
44 private_.Reset();
45 }
46
Assign(const WebHTTPLoadInfo & r)47 void WebHTTPLoadInfo::Assign(const WebHTTPLoadInfo& r) {
48 private_ = r.private_;
49 }
50
WebHTTPLoadInfo(scoped_refptr<ResourceLoadInfo> value)51 WebHTTPLoadInfo::WebHTTPLoadInfo(scoped_refptr<ResourceLoadInfo> value)
52 : private_(std::move(value)) {}
53
operator scoped_refptr<ResourceLoadInfo>() const54 WebHTTPLoadInfo::operator scoped_refptr<ResourceLoadInfo>() const {
55 return private_.Get();
56 }
57
HttpStatusCode() const58 int WebHTTPLoadInfo::HttpStatusCode() const {
59 DCHECK(!private_.IsNull());
60 return private_->http_status_code;
61 }
62
SetHTTPStatusCode(int status_code)63 void WebHTTPLoadInfo::SetHTTPStatusCode(int status_code) {
64 DCHECK(!private_.IsNull());
65 private_->http_status_code = status_code;
66 }
67
HttpStatusText() const68 WebString WebHTTPLoadInfo::HttpStatusText() const {
69 DCHECK(!private_.IsNull());
70 return private_->http_status_text;
71 }
72
SetHTTPStatusText(const WebString & status_text)73 void WebHTTPLoadInfo::SetHTTPStatusText(const WebString& status_text) {
74 DCHECK(!private_.IsNull());
75 private_->http_status_text = status_text;
76 }
77
AddHeader(HTTPHeaderMap * map,const WebString & name,const WebString & value)78 static void AddHeader(HTTPHeaderMap* map,
79 const WebString& name,
80 const WebString& value) {
81 HTTPHeaderMap::AddResult result = map->Add(name, value);
82 // It is important that values are separated by '\n', not comma, otherwise
83 // Set-Cookie header is not parseable.
84 if (!result.is_new_entry)
85 result.stored_value->value =
86 result.stored_value->value + "\n" + String(value);
87 }
88
AddRequestHeader(const WebString & name,const WebString & value)89 void WebHTTPLoadInfo::AddRequestHeader(const WebString& name,
90 const WebString& value) {
91 DCHECK(!private_.IsNull());
92 AddHeader(&private_->request_headers, name, value);
93 }
94
AddResponseHeader(const WebString & name,const WebString & value)95 void WebHTTPLoadInfo::AddResponseHeader(const WebString& name,
96 const WebString& value) {
97 DCHECK(!private_.IsNull());
98 AddHeader(&private_->response_headers, name, value);
99 }
100
RequestHeadersText() const101 WebString WebHTTPLoadInfo::RequestHeadersText() const {
102 DCHECK(!private_.IsNull());
103 return private_->request_headers_text;
104 }
105
SetRequestHeadersText(const WebString & headers_text)106 void WebHTTPLoadInfo::SetRequestHeadersText(const WebString& headers_text) {
107 DCHECK(!private_.IsNull());
108 private_->request_headers_text = headers_text;
109 }
110
ResponseHeadersText() const111 WebString WebHTTPLoadInfo::ResponseHeadersText() const {
112 DCHECK(!private_.IsNull());
113 return private_->response_headers_text;
114 }
115
SetResponseHeadersText(const WebString & headers_text)116 void WebHTTPLoadInfo::SetResponseHeadersText(const WebString& headers_text) {
117 DCHECK(!private_.IsNull());
118 private_->response_headers_text = headers_text;
119 }
120
121 } // namespace blink
122