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 "WebHTTPLoadInfo.h"
33
34#include "ResourceLoadInfo.h"
35#include "ResourceResponse.h"
36#include "WebHTTPHeaderVisitor.h"
37#include "WebString.h"
38
39using namespace WebCore;
40
41namespace WebKit {
42
43void WebHTTPLoadInfo::initialize()
44{
45    m_private = adoptRef(new ResourceLoadInfo());
46}
47
48void WebHTTPLoadInfo::reset()
49{
50    m_private.reset();
51}
52
53void WebHTTPLoadInfo::assign(const WebHTTPLoadInfo& r)
54{
55    m_private = r.m_private;
56}
57
58WebHTTPLoadInfo::WebHTTPLoadInfo(WTF::PassRefPtr<WebCore::ResourceLoadInfo> value)
59{
60    m_private = value;
61}
62
63WebHTTPLoadInfo::operator WTF::PassRefPtr<WebCore::ResourceLoadInfo>() const
64{
65    return m_private.get();
66}
67
68int WebHTTPLoadInfo::httpStatusCode() const
69{
70    ASSERT(!m_private.isNull());
71    return m_private->httpStatusCode;
72}
73
74void WebHTTPLoadInfo::setHTTPStatusCode(int statusCode)
75{
76    ASSERT(!m_private.isNull());
77    m_private->httpStatusCode = statusCode;
78}
79
80WebString WebHTTPLoadInfo::httpStatusText() const
81{
82    ASSERT(!m_private.isNull());
83    return m_private->httpStatusText;
84}
85
86void WebHTTPLoadInfo::setHTTPStatusText(const WebString& statusText)
87{
88    ASSERT(!m_private.isNull());
89    m_private->httpStatusText = statusText;
90}
91
92long long WebHTTPLoadInfo::encodedDataLength() const
93{
94    ASSERT(!m_private.isNull());
95    return m_private->encodedDataLength;
96}
97
98void WebHTTPLoadInfo::setEncodedDataLength(long long encodedDataLength)
99{
100    ASSERT(!m_private.isNull());
101    m_private->encodedDataLength = encodedDataLength;
102}
103
104static void addHeader(HTTPHeaderMap* map, const WebString& name, const WebString& value)
105{
106    pair<HTTPHeaderMap::iterator, bool> result = map->add(name, value);
107    if (!result.second)
108        result.first->second += String("\n") + value;
109}
110
111void WebHTTPLoadInfo::addRequestHeader(const WebString& name, const WebString& value)
112{
113    ASSERT(!m_private.isNull());
114    addHeader(&m_private->requestHeaders, name, value);
115}
116
117void WebHTTPLoadInfo::addResponseHeader(const WebString& name, const WebString& value)
118{
119    ASSERT(!m_private.isNull());
120    addHeader(&m_private->responseHeaders, name, value);
121}
122
123WebString WebHTTPLoadInfo::requestHeadersText() const
124{
125    ASSERT(!m_private.isNull());
126    return m_private->requestHeadersText;
127}
128
129void WebHTTPLoadInfo::setRequestHeadersText(const WebString& headersText)
130{
131    ASSERT(!m_private.isNull());
132    m_private->requestHeadersText = headersText;
133}
134
135WebString WebHTTPLoadInfo::responseHeadersText() const
136{
137    ASSERT(!m_private.isNull());
138    return m_private->responseHeadersText;
139}
140
141void WebHTTPLoadInfo::setResponseHeadersText(const WebString& headersText)
142{
143    ASSERT(!m_private.isNull());
144    m_private->responseHeadersText = headersText;
145}
146
147} // namespace WebKit
148