2
* Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
3
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
4
* Copyright (C) 2009, 2012 Google Inc. All rights reserved.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#ifndef ResourceRequestBase_h
29
#define ResourceRequestBase_h
32
#include "HTTPHeaderMap.h"
34
#include "ResourceLoadPriority.h"
36
#include <wtf/OwnPtr.h>
40
enum ResourceRequestCachePolicy {
41
UseProtocolCachePolicy, // normal load
42
ReloadIgnoringCacheData, // reload
43
ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale data
44
ReturnCacheDataDontLoad // results of a post - allow stale data and only use cache
47
class ResourceRequest;
48
struct CrossThreadResourceRequestData;
50
// Do not use this type directly. Use ResourceRequest instead.
51
class ResourceRequestBase {
52
WTF_MAKE_FAST_ALLOCATED;
54
static PassOwnPtr<ResourceRequest> adopt(PassOwnPtr<CrossThreadResourceRequestData>);
56
// Gets a copy of the data suitable for passing to another thread.
57
PassOwnPtr<CrossThreadResourceRequestData> copyData() const;
62
const KURL& url() const;
63
void setURL(const KURL& url);
65
void removeCredentials();
67
ResourceRequestCachePolicy cachePolicy() const;
68
void setCachePolicy(ResourceRequestCachePolicy cachePolicy);
70
double timeoutInterval() const; // May return 0 when using platform default.
71
void setTimeoutInterval(double timeoutInterval);
73
const KURL& firstPartyForCookies() const;
74
void setFirstPartyForCookies(const KURL& firstPartyForCookies);
76
const String& httpMethod() const;
77
void setHTTPMethod(const String& httpMethod);
79
const HTTPHeaderMap& httpHeaderFields() const;
80
String httpHeaderField(const AtomicString& name) const;
81
String httpHeaderField(const char* name) const;
82
void setHTTPHeaderField(const AtomicString& name, const String& value);
83
void setHTTPHeaderField(const char* name, const String& value);
84
void addHTTPHeaderField(const AtomicString& name, const String& value);
85
void addHTTPHeaderFields(const HTTPHeaderMap& headerFields);
87
void clearHTTPAuthorization();
89
String httpContentType() const { return httpHeaderField("Content-Type"); }
90
void setHTTPContentType(const String& httpContentType) { setHTTPHeaderField("Content-Type", httpContentType); }
91
void clearHTTPContentType();
93
String httpReferrer() const { return httpHeaderField("Referer"); }
94
void setHTTPReferrer(const String& httpReferrer) { setHTTPHeaderField("Referer", httpReferrer); }
95
void clearHTTPReferrer();
97
String httpOrigin() const { return httpHeaderField("Origin"); }
98
void setHTTPOrigin(const String& httpOrigin) { setHTTPHeaderField("Origin", httpOrigin); }
99
void clearHTTPOrigin();
101
String httpUserAgent() const { return httpHeaderField("User-Agent"); }
102
void setHTTPUserAgent(const String& httpUserAgent) { setHTTPHeaderField("User-Agent", httpUserAgent); }
103
void clearHTTPUserAgent();
105
String httpAccept() const { return httpHeaderField("Accept"); }
106
void setHTTPAccept(const String& httpAccept) { setHTTPHeaderField("Accept", httpAccept); }
107
void clearHTTPAccept();
109
void setResponseContentDispositionEncodingFallbackArray(const String& encoding1, const String& encoding2 = String(), const String& encoding3 = String());
111
FormData* httpBody() const;
112
void setHTTPBody(PassRefPtr<FormData> httpBody);
114
bool allowCookies() const;
115
void setAllowCookies(bool allowCookies);
117
ResourceLoadPriority priority() const;
118
void setPriority(ResourceLoadPriority);
120
bool isConditional() const;
122
// Whether the associated ResourceHandleClient needs to be notified of
123
// upload progress made for that resource.
124
bool reportUploadProgress() const { return m_reportUploadProgress; }
125
void setReportUploadProgress(bool reportUploadProgress) { m_reportUploadProgress = reportUploadProgress; }
127
// Whether the timing information should be collected for the request.
128
bool reportLoadTiming() const { return m_reportLoadTiming; }
129
void setReportLoadTiming(bool reportLoadTiming) { m_reportLoadTiming = reportLoadTiming; }
131
// Whether actual headers being sent/received should be collected and reported for the request.
132
bool reportRawHeaders() const { return m_reportRawHeaders; }
133
void setReportRawHeaders(bool reportRawHeaders) { m_reportRawHeaders = reportRawHeaders; }
135
static double defaultTimeoutInterval(); // May return 0 when using platform default.
136
static void setDefaultTimeoutInterval(double);
138
static bool compare(const ResourceRequest&, const ResourceRequest&);
141
// Used when ResourceRequest is initialized from a platform representation of the request
142
ResourceRequestBase()
143
: m_resourceRequestUpdated(false)
144
, m_platformRequestUpdated(true)
145
, m_reportUploadProgress(false)
146
, m_reportLoadTiming(false)
147
, m_reportRawHeaders(false)
148
, m_priority(ResourceLoadPriorityLow)
152
ResourceRequestBase(const KURL& url, ResourceRequestCachePolicy policy)
154
, m_cachePolicy(policy)
155
, m_timeoutInterval(s_defaultTimeoutInterval)
156
, m_httpMethod("GET")
157
, m_allowCookies(true)
158
, m_resourceRequestUpdated(true)
159
, m_platformRequestUpdated(false)
160
, m_reportUploadProgress(false)
161
, m_reportLoadTiming(false)
162
, m_reportRawHeaders(false)
163
, m_priority(ResourceLoadPriorityLow)
167
void updatePlatformRequest() const;
168
void updateResourceRequest() const;
170
void reportMemoryUsageBase(MemoryObjectInfo*) const;
172
// The ResourceRequest subclass may "shadow" this method to compare platform specific fields
173
static bool platformCompare(const ResourceRequest&, const ResourceRequest&) { return true; }
177
ResourceRequestCachePolicy m_cachePolicy;
178
double m_timeoutInterval; // 0 is a magic value for platform default on platforms that have one.
179
KURL m_firstPartyForCookies;
181
HTTPHeaderMap m_httpHeaderFields;
182
Vector<String> m_responseContentDispositionEncodingFallbackArray;
183
RefPtr<FormData> m_httpBody;
184
bool m_allowCookies : 1;
185
mutable bool m_resourceRequestUpdated : 1;
186
mutable bool m_platformRequestUpdated : 1;
187
bool m_reportUploadProgress : 1;
188
bool m_reportLoadTiming : 1;
189
bool m_reportRawHeaders : 1;
190
ResourceLoadPriority m_priority;
193
const ResourceRequest& asResourceRequest() const;
195
static double s_defaultTimeoutInterval;
198
bool equalIgnoringHeaderFields(const ResourceRequestBase&, const ResourceRequestBase&);
200
inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { return ResourceRequestBase::compare(a, b); }
201
inline bool operator!=(ResourceRequest& a, const ResourceRequest& b) { return !(a == b); }
203
struct CrossThreadResourceRequestDataBase {
204
WTF_MAKE_NONCOPYABLE(CrossThreadResourceRequestDataBase); WTF_MAKE_FAST_ALLOCATED;
206
CrossThreadResourceRequestDataBase() { }
209
ResourceRequestCachePolicy m_cachePolicy;
210
double m_timeoutInterval;
211
KURL m_firstPartyForCookies;
214
OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
215
Vector<String> m_responseContentDispositionEncodingFallbackArray;
216
RefPtr<FormData> m_httpBody;
218
ResourceLoadPriority m_priority;
221
unsigned initializeMaximumHTTPConnectionCountPerHost();
223
} // namespace WebCore
225
#endif // ResourceRequestBase_h