2 * Copyright (C) 2009 Gustavo Noronha Silva
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "ResourceRequest.h"
24 #include "GOwnPtrSoup.h"
25 #include "HTTPParsers.h"
26 #include "MIMETypeRegistry.h"
27 #include "PlatformString.h"
28 #include "SoupURIUtils.h"
29 #include <wtf/text/CString.h>
31 #include <libsoup/soup.h>
37 void ResourceRequest::updateSoupMessage(SoupMessage* soupMessage) const
39 g_object_set(soupMessage, SOUP_MESSAGE_METHOD, httpMethod().utf8().data(), NULL);
41 const HTTPHeaderMap& headers = httpHeaderFields();
42 SoupMessageHeaders* soupHeaders = soupMessage->request_headers;
43 if (!headers.isEmpty()) {
44 HTTPHeaderMap::const_iterator end = headers.end();
45 for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it)
46 soup_message_headers_append(soupHeaders, it->first.string().utf8().data(), it->second.utf8().data());
49 String firstPartyString = firstPartyForCookies().string();
50 if (!firstPartyString.isEmpty()) {
51 GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data()));
52 soup_message_set_first_party(soupMessage, firstParty.get());
55 soup_message_set_flags(soupMessage, m_soupFlags);
58 SoupMessage* ResourceRequest::toSoupMessage() const
60 SoupMessage* soupMessage = soup_message_new(httpMethod().utf8().data(), url().string().utf8().data());
64 const HTTPHeaderMap& headers = httpHeaderFields();
65 SoupMessageHeaders* soupHeaders = soupMessage->request_headers;
66 if (!headers.isEmpty()) {
67 HTTPHeaderMap::const_iterator end = headers.end();
68 for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it)
69 soup_message_headers_append(soupHeaders, it->first.string().utf8().data(), it->second.utf8().data());
72 String firstPartyString = firstPartyForCookies().string();
73 if (!firstPartyString.isEmpty()) {
74 GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data()));
75 soup_message_set_first_party(soupMessage, firstParty.get());
78 soup_message_set_flags(soupMessage, m_soupFlags);
80 // Body data is only handled at ResourceHandleSoup::startHttp for
81 // now; this is because this may not be a good place to go
82 // openning and mmapping files. We should maybe revisit this.
86 void ResourceRequest::updateFromSoupMessage(SoupMessage* soupMessage)
88 m_url = soupURIToKURL(soup_message_get_uri(soupMessage));
90 m_httpMethod = String::fromUTF8(soupMessage->method);
92 m_httpHeaderFields.clear();
93 SoupMessageHeadersIter headersIter;
94 const char* headerName;
95 const char* headerValue;
96 soup_message_headers_iter_init(&headersIter, soupMessage->request_headers);
97 while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue)) {
98 m_httpHeaderFields.set(String::fromUTF8(headerName), String::fromUTF8(headerValue));
101 if (soupMessage->request_body->data)
102 m_httpBody = FormData::create(soupMessage->request_body->data, soupMessage->request_body->length);
104 SoupURI* firstParty = soup_message_get_first_party(soupMessage);
106 m_firstPartyForCookies = soupURIToKURL(firstParty);
108 m_soupFlags = soup_message_get_flags(soupMessage);
110 // FIXME: m_allowCookies should probably be handled here and on
111 // doUpdatePlatformRequest somehow.
114 unsigned initializeMaximumHTTPConnectionCountPerHost()
116 // Soup has its own queue control; it wants to have all requests
117 // given to it, so that it is able to look ahead, and schedule
118 // them in a good way.