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