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 "core/platform/network/ResourceLoadInfo.h" 35#include "public/platform/WebHTTPHeaderVisitor.h" 36#include "public/platform/WebString.h" 37 38using namespace WebCore; 39 40namespace WebKit { 41 42void WebHTTPLoadInfo::initialize() 43{ 44 m_private = adoptRef(new ResourceLoadInfo()); 45} 46 47void WebHTTPLoadInfo::reset() 48{ 49 m_private.reset(); 50} 51 52void WebHTTPLoadInfo::assign(const WebHTTPLoadInfo& r) 53{ 54 m_private = r.m_private; 55} 56 57WebHTTPLoadInfo::WebHTTPLoadInfo(WTF::PassRefPtr<WebCore::ResourceLoadInfo> value) 58{ 59 m_private = value; 60} 61 62WebHTTPLoadInfo::operator WTF::PassRefPtr<WebCore::ResourceLoadInfo>() const 63{ 64 return m_private.get(); 65} 66 67int WebHTTPLoadInfo::httpStatusCode() const 68{ 69 ASSERT(!m_private.isNull()); 70 return m_private->httpStatusCode; 71} 72 73void WebHTTPLoadInfo::setHTTPStatusCode(int statusCode) 74{ 75 ASSERT(!m_private.isNull()); 76 m_private->httpStatusCode = statusCode; 77} 78 79WebString WebHTTPLoadInfo::httpStatusText() const 80{ 81 ASSERT(!m_private.isNull()); 82 return m_private->httpStatusText; 83} 84 85void WebHTTPLoadInfo::setHTTPStatusText(const WebString& statusText) 86{ 87 ASSERT(!m_private.isNull()); 88 m_private->httpStatusText = statusText; 89} 90 91long long WebHTTPLoadInfo::encodedDataLength() const 92{ 93 ASSERT(!m_private.isNull()); 94 return m_private->encodedDataLength; 95} 96 97void WebHTTPLoadInfo::setEncodedDataLength(long long encodedDataLength) 98{ 99 ASSERT(!m_private.isNull()); 100 m_private->encodedDataLength = encodedDataLength; 101} 102 103static void addHeader(HTTPHeaderMap* map, const WebString& name, const WebString& value) 104{ 105 HTTPHeaderMap::AddResult result = map->add(name, value); 106 // It is important that values are separated by '\n', not comma, otherwise Set-Cookie header is not parseable. 107 if (!result.isNewEntry) 108 result.iterator->value = result.iterator->value + "\n" + String(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