1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright (C) 2009 Gustavo Noronha Silva
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "ResourceRequest.h"
#include <wtf/gobject/GOwnPtr.h>
#include "GOwnPtrSoup.h"
#include "HTTPParsers.h"
#include "MIMETypeRegistry.h"
#include "SoupURIUtils.h"
#include <libsoup/soup.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
using namespace std;
namespace WebCore {
void ResourceRequest::updateSoupMessage(SoupMessage* soupMessage) const
{
g_object_set(soupMessage, SOUP_MESSAGE_METHOD, httpMethod().utf8().data(), NULL);
const HTTPHeaderMap& headers = httpHeaderFields();
SoupMessageHeaders* soupHeaders = soupMessage->request_headers;
if (!headers.isEmpty()) {
HTTPHeaderMap::const_iterator end = headers.end();
for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it)
soup_message_headers_append(soupHeaders, it->first.string().utf8().data(), it->second.utf8().data());
}
String firstPartyString = firstPartyForCookies().string();
if (!firstPartyString.isEmpty()) {
GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data()));
soup_message_set_first_party(soupMessage, firstParty.get());
}
soup_message_set_flags(soupMessage, m_soupFlags);
}
SoupMessage* ResourceRequest::toSoupMessage() const
{
SoupMessage* soupMessage = soup_message_new(httpMethod().utf8().data(), url().string().utf8().data());
if (!soupMessage)
return 0;
const HTTPHeaderMap& headers = httpHeaderFields();
SoupMessageHeaders* soupHeaders = soupMessage->request_headers;
if (!headers.isEmpty()) {
HTTPHeaderMap::const_iterator end = headers.end();
for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it)
soup_message_headers_append(soupHeaders, it->first.string().utf8().data(), it->second.utf8().data());
}
String firstPartyString = firstPartyForCookies().string();
if (!firstPartyString.isEmpty()) {
GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data()));
soup_message_set_first_party(soupMessage, firstParty.get());
}
soup_message_set_flags(soupMessage, m_soupFlags);
// Body data is only handled at ResourceHandleSoup::startHttp for
// now; this is because this may not be a good place to go
// openning and mmapping files. We should maybe revisit this.
return soupMessage;
}
void ResourceRequest::updateFromSoupMessage(SoupMessage* soupMessage)
{
bool shouldPortBeResetToZero = m_url.hasPort() && !m_url.port();
m_url = soupURIToKURL(soup_message_get_uri(soupMessage));
// SoupURI cannot differeniate between an explicitly specified port 0 and
// no port specified.
if (shouldPortBeResetToZero)
m_url.setPort(0);
m_httpMethod = String::fromUTF8(soupMessage->method);
m_httpHeaderFields.clear();
SoupMessageHeadersIter headersIter;
const char* headerName;
const char* headerValue;
soup_message_headers_iter_init(&headersIter, soupMessage->request_headers);
while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue))
m_httpHeaderFields.set(String::fromUTF8(headerName), String::fromUTF8(headerValue));
if (soupMessage->request_body->data)
m_httpBody = FormData::create(soupMessage->request_body->data, soupMessage->request_body->length);
SoupURI* firstParty = soup_message_get_first_party(soupMessage);
if (firstParty)
m_firstPartyForCookies = soupURIToKURL(firstParty);
m_soupFlags = soup_message_get_flags(soupMessage);
// FIXME: m_allowCookies should probably be handled here and on
// doUpdatePlatformRequest somehow.
}
unsigned initializeMaximumHTTPConnectionCountPerHost()
{
// Soup has its own queue control; it wants to have all requests
// given to it, so that it is able to look ahead, and schedule
// them in a good way.
return 10000;
}
}
|