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 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); }
92 String httpReferrer() const { return httpHeaderField("Referer"); }
93 void setHTTPReferrer(const String& httpReferrer) { setHTTPHeaderField("Referer", httpReferrer); }
94 void clearHTTPReferrer();
96 String httpOrigin() const { return httpHeaderField("Origin"); }
97 void setHTTPOrigin(const String& httpOrigin) { setHTTPHeaderField("Origin", httpOrigin); }
98 void clearHTTPOrigin();
100 String httpUserAgent() const { return httpHeaderField("User-Agent"); }
101 void setHTTPUserAgent(const String& httpUserAgent) { setHTTPHeaderField("User-Agent", httpUserAgent); }
103 String httpAccept() const { return httpHeaderField("Accept"); }
104 void setHTTPAccept(const String& httpAccept) { setHTTPHeaderField("Accept", httpAccept); }
106 #if PLATFORM(MAC) || PLATFORM(WIN)
107 // FIXME: This state should either be moved to a CFNetwork-specific
108 // ResourceRequest or should be removed.
109 void setResponseContentDispositionEncodingFallbackArray(const String& encoding1, const String& encoding2 = String(), const String& encoding3 = String());
112 FormData* httpBody() const;
113 void setHTTPBody(PassRefPtr<FormData> httpBody);
115 bool allowCookies() const;
116 void setAllowCookies(bool allowCookies);
118 ResourceLoadPriority priority() const;
119 void setPriority(ResourceLoadPriority);
121 bool isConditional() const;
123 // Whether the associated ResourceHandleClient needs to be notified of
124 // upload progress made for that resource.
125 bool reportUploadProgress() const { return m_reportUploadProgress; }
126 void setReportUploadProgress(bool reportUploadProgress) { m_reportUploadProgress = reportUploadProgress; }
128 // Whether the timing information should be collected for the request.
129 bool reportLoadTiming() const { return m_reportLoadTiming; }
130 void setReportLoadTiming(bool reportLoadTiming) { m_reportLoadTiming = reportLoadTiming; }
132 // Whether actual headers being sent/received should be collected and reported for the request.
133 bool reportRawHeaders() const { return m_reportRawHeaders; }
134 void setReportRawHeaders(bool reportRawHeaders) { m_reportRawHeaders = reportRawHeaders; }
136 static double defaultTimeoutInterval(); // May return 0 when using platform default.
137 static void setDefaultTimeoutInterval(double);
139 static bool compare(const ResourceRequest&, const ResourceRequest&);
142 // Used when ResourceRequest is initialized from a platform representation of the request
143 ResourceRequestBase()
144 : m_resourceRequestUpdated(false)
145 , m_platformRequestUpdated(true)
146 , m_reportUploadProgress(false)
147 , m_reportLoadTiming(false)
148 , m_reportRawHeaders(false)
149 , m_priority(ResourceLoadPriorityLow)
153 ResourceRequestBase(const KURL& url, ResourceRequestCachePolicy policy)
155 , m_cachePolicy(policy)
156 , m_timeoutInterval(s_defaultTimeoutInterval)
157 , m_httpMethod("GET")
158 , m_allowCookies(true)
159 , m_resourceRequestUpdated(true)
160 , m_platformRequestUpdated(false)
161 , m_reportUploadProgress(false)
162 , m_reportLoadTiming(false)
163 , m_reportRawHeaders(false)
164 , m_priority(ResourceLoadPriorityLow)
168 void updatePlatformRequest() const;
169 void updateResourceRequest() const;
171 // The ResourceRequest subclass may "shadow" this method to compare platform specific fields
172 static bool platformCompare(const ResourceRequest&, const ResourceRequest&) { return true; }
176 ResourceRequestCachePolicy m_cachePolicy;
177 double m_timeoutInterval; // 0 is a magic value for platform default on platforms that have one.
178 KURL m_firstPartyForCookies;
180 HTTPHeaderMap m_httpHeaderFields;
181 #if PLATFORM(MAC) || PLATFORM(WIN)
182 // FIXME: This state should either be moved to a CFNetwork-specific
183 // ResourceRequest or should be removed.
184 Vector<String> m_responseContentDispositionEncodingFallbackArray;
186 RefPtr<FormData> m_httpBody;
188 mutable bool m_resourceRequestUpdated;
189 mutable bool m_platformRequestUpdated;
190 bool m_reportUploadProgress;
191 bool m_reportLoadTiming;
192 bool m_reportRawHeaders;
193 ResourceLoadPriority m_priority;
196 const ResourceRequest& asResourceRequest() const;
198 static double s_defaultTimeoutInterval;
201 bool equalIgnoringHeaderFields(const ResourceRequestBase&, const ResourceRequestBase&);
203 inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { return ResourceRequestBase::compare(a, b); }
204 inline bool operator!=(ResourceRequest& a, const ResourceRequest& b) { return !(a == b); }
206 struct CrossThreadResourceRequestDataBase {
207 WTF_MAKE_NONCOPYABLE(CrossThreadResourceRequestDataBase); WTF_MAKE_FAST_ALLOCATED;
209 CrossThreadResourceRequestDataBase() { }
212 ResourceRequestCachePolicy m_cachePolicy;
213 double m_timeoutInterval;
214 KURL m_firstPartyForCookies;
217 OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
218 #if PLATFORM(MAC) || PLATFORM(WIN)
219 Vector<String> m_responseContentDispositionEncodingFallbackArray;
221 RefPtr<FormData> m_httpBody;
223 ResourceLoadPriority m_priority;
226 unsigned initializeMaximumHTTPConnectionCountPerHost();
228 } // namespace WebCore
230 #endif // ResourceRequestBase_h