• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "config.h"
32 #include "public/platform/WebHTTPLoadInfo.h"
33 
34 #include "platform/network/ResourceLoadInfo.h"
35 #include "public/platform/WebHTTPHeaderVisitor.h"
36 #include "public/platform/WebString.h"
37 
38 namespace blink {
39 
initialize()40 void WebHTTPLoadInfo::initialize()
41 {
42     m_private = adoptRef(new ResourceLoadInfo());
43 }
44 
reset()45 void WebHTTPLoadInfo::reset()
46 {
47     m_private.reset();
48 }
49 
assign(const WebHTTPLoadInfo & r)50 void WebHTTPLoadInfo::assign(const WebHTTPLoadInfo& r)
51 {
52     m_private = r.m_private;
53 }
54 
WebHTTPLoadInfo(WTF::PassRefPtr<ResourceLoadInfo> value)55 WebHTTPLoadInfo::WebHTTPLoadInfo(WTF::PassRefPtr<ResourceLoadInfo> value)
56     : m_private(value)
57 {
58 }
59 
operator WTF::PassRefPtr<ResourceLoadInfo>() const60 WebHTTPLoadInfo::operator WTF::PassRefPtr<ResourceLoadInfo>() const
61 {
62     return m_private.get();
63 }
64 
httpStatusCode() const65 int WebHTTPLoadInfo::httpStatusCode() const
66 {
67     ASSERT(!m_private.isNull());
68     return m_private->httpStatusCode;
69 }
70 
setHTTPStatusCode(int statusCode)71 void WebHTTPLoadInfo::setHTTPStatusCode(int statusCode)
72 {
73     ASSERT(!m_private.isNull());
74     m_private->httpStatusCode = statusCode;
75 }
76 
httpStatusText() const77 WebString WebHTTPLoadInfo::httpStatusText() const
78 {
79     ASSERT(!m_private.isNull());
80     return m_private->httpStatusText;
81 }
82 
setHTTPStatusText(const WebString & statusText)83 void WebHTTPLoadInfo::setHTTPStatusText(const WebString& statusText)
84 {
85     ASSERT(!m_private.isNull());
86     m_private->httpStatusText = statusText;
87 }
88 
encodedDataLength() const89 long long WebHTTPLoadInfo::encodedDataLength() const
90 {
91     ASSERT(!m_private.isNull());
92     return m_private->encodedDataLength;
93 }
94 
setEncodedDataLength(long long encodedDataLength)95 void WebHTTPLoadInfo::setEncodedDataLength(long long encodedDataLength)
96 {
97     ASSERT(!m_private.isNull());
98     m_private->encodedDataLength = encodedDataLength;
99 }
100 
addHeader(HTTPHeaderMap * map,const WebString & name,const WebString & value)101 static void addHeader(HTTPHeaderMap* map, const WebString& name, const WebString& value)
102 {
103     HTTPHeaderMap::AddResult result = map->add(name, value);
104     // It is important that values are separated by '\n', not comma, otherwise Set-Cookie header is not parseable.
105     if (!result.isNewEntry)
106         result.storedValue->value = result.storedValue->value + "\n" + String(value);
107 }
108 
addRequestHeader(const WebString & name,const WebString & value)109 void WebHTTPLoadInfo::addRequestHeader(const WebString& name, const WebString& value)
110 {
111     ASSERT(!m_private.isNull());
112     addHeader(&m_private->requestHeaders, name, value);
113 }
114 
addResponseHeader(const WebString & name,const WebString & value)115 void WebHTTPLoadInfo::addResponseHeader(const WebString& name, const WebString& value)
116 {
117     ASSERT(!m_private.isNull());
118     addHeader(&m_private->responseHeaders, name, value);
119 }
120 
requestHeadersText() const121 WebString WebHTTPLoadInfo::requestHeadersText() const
122 {
123     ASSERT(!m_private.isNull());
124     return m_private->requestHeadersText;
125 }
126 
setRequestHeadersText(const WebString & headersText)127 void WebHTTPLoadInfo::setRequestHeadersText(const WebString& headersText)
128 {
129     ASSERT(!m_private.isNull());
130     m_private->requestHeadersText = headersText;
131 }
132 
responseHeadersText() const133 WebString WebHTTPLoadInfo::responseHeadersText() const
134 {
135     ASSERT(!m_private.isNull());
136     return m_private->responseHeadersText;
137 }
138 
setResponseHeadersText(const WebString & headersText)139 void WebHTTPLoadInfo::setResponseHeadersText(const WebString& headersText)
140 {
141     ASSERT(!m_private.isNull());
142     m_private->responseHeadersText = headersText;
143 }
144 
145 } // namespace blink
146