2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "public/platform/WebHTTPLoadInfo.h"
34 #include "platform/network/ResourceLoadInfo.h"
35 #include "public/platform/WebHTTPHeaderVisitor.h"
36 #include "public/platform/WebString.h"
40 void WebHTTPLoadInfo::initialize()
42 m_private
= adoptRef(new ResourceLoadInfo());
45 void WebHTTPLoadInfo::reset()
50 void WebHTTPLoadInfo::assign(const WebHTTPLoadInfo
& r
)
52 m_private
= r
.m_private
;
55 WebHTTPLoadInfo::WebHTTPLoadInfo(WTF::PassRefPtr
<ResourceLoadInfo
> value
)
60 WebHTTPLoadInfo::operator WTF::PassRefPtr
<ResourceLoadInfo
>() const
62 return m_private
.get();
65 int WebHTTPLoadInfo::httpStatusCode() const
67 ASSERT(!m_private
.isNull());
68 return m_private
->httpStatusCode
;
71 void WebHTTPLoadInfo::setHTTPStatusCode(int statusCode
)
73 ASSERT(!m_private
.isNull());
74 m_private
->httpStatusCode
= statusCode
;
77 WebString
WebHTTPLoadInfo::httpStatusText() const
79 ASSERT(!m_private
.isNull());
80 return m_private
->httpStatusText
;
83 void WebHTTPLoadInfo::setHTTPStatusText(const WebString
& statusText
)
85 ASSERT(!m_private
.isNull());
86 m_private
->httpStatusText
= statusText
;
89 long long WebHTTPLoadInfo::encodedDataLength() const
91 ASSERT(!m_private
.isNull());
92 return m_private
->encodedDataLength
;
95 void WebHTTPLoadInfo::setEncodedDataLength(long long encodedDataLength
)
97 ASSERT(!m_private
.isNull());
98 m_private
->encodedDataLength
= encodedDataLength
;
101 static void addHeader(HTTPHeaderMap
* map
, const WebString
& name
, const WebString
& value
)
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
);
109 void WebHTTPLoadInfo::addRequestHeader(const WebString
& name
, const WebString
& value
)
111 ASSERT(!m_private
.isNull());
112 addHeader(&m_private
->requestHeaders
, name
, value
);
115 void WebHTTPLoadInfo::addResponseHeader(const WebString
& name
, const WebString
& value
)
117 ASSERT(!m_private
.isNull());
118 addHeader(&m_private
->responseHeaders
, name
, value
);
121 WebString
WebHTTPLoadInfo::requestHeadersText() const
123 ASSERT(!m_private
.isNull());
124 return m_private
->requestHeadersText
;
127 void WebHTTPLoadInfo::setRequestHeadersText(const WebString
& headersText
)
129 ASSERT(!m_private
.isNull());
130 m_private
->requestHeadersText
= headersText
;
133 WebString
WebHTTPLoadInfo::responseHeadersText() const
135 ASSERT(!m_private
.isNull());
136 return m_private
->responseHeadersText
;
139 void WebHTTPLoadInfo::setResponseHeadersText(const WebString
& headersText
)
141 ASSERT(!m_private
.isNull());
142 m_private
->responseHeadersText
= headersText
;
145 WebString
WebHTTPLoadInfo::npnNegotiatedProtocol() const
147 ASSERT(!m_private
.isNull());
148 return m_private
->npnNegotiatedProtocol
;
151 void WebHTTPLoadInfo::setNPNNegotiatedProtocol(const WebString
& npnNegotiatedProtocol
)
153 ASSERT(!m_private
.isNull());
154 m_private
->npnNegotiatedProtocol
= npnNegotiatedProtocol
;