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
33 #include "HTTPHeaderMap.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 const int unspecifiedTimeoutInterval
= INT_MAX
;
49 class ResourceRequest
;
50 struct CrossThreadResourceRequestData
;
52 // Do not use this type directly. Use ResourceRequest instead.
53 class ResourceRequestBase
{
55 static std::auto_ptr
<ResourceRequest
> adopt(std::auto_ptr
<CrossThreadResourceRequestData
>);
57 // Gets a copy of the data suitable for passing to another thread.
58 std::auto_ptr
<CrossThreadResourceRequestData
> copyData() const;
63 const KURL
& url() const;
64 void setURL(const KURL
& url
);
66 ResourceRequestCachePolicy
cachePolicy() const;
67 void setCachePolicy(ResourceRequestCachePolicy cachePolicy
);
69 double timeoutInterval() const;
70 void setTimeoutInterval(double timeoutInterval
);
72 const KURL
& mainDocumentURL() const;
73 void setMainDocumentURL(const KURL
& mainDocumentURL
);
75 const String
& httpMethod() const;
76 void setHTTPMethod(const String
& httpMethod
);
78 const HTTPHeaderMap
& httpHeaderFields() const;
79 String
httpHeaderField(const AtomicString
& name
) const;
80 void setHTTPHeaderField(const AtomicString
& name
, const String
& value
);
81 void addHTTPHeaderField(const AtomicString
& name
, const String
& value
);
82 void addHTTPHeaderFields(const HTTPHeaderMap
& headerFields
);
84 String
httpContentType() const { return httpHeaderField("Content-Type"); }
85 void setHTTPContentType(const String
& httpContentType
) { setHTTPHeaderField("Content-Type", httpContentType
); }
87 String
httpReferrer() const { return httpHeaderField("Referer"); }
88 void setHTTPReferrer(const String
& httpReferrer
) { setHTTPHeaderField("Referer", httpReferrer
); }
89 void clearHTTPReferrer() { m_httpHeaderFields
.remove("Referer"); }
91 String
httpOrigin() const { return httpHeaderField("Origin"); }
92 void setHTTPOrigin(const String
& httpOrigin
) { setHTTPHeaderField("Origin", httpOrigin
); }
93 void clearHTTPOrigin() { m_httpHeaderFields
.remove("Origin"); }
95 String
httpUserAgent() const { return httpHeaderField("User-Agent"); }
96 void setHTTPUserAgent(const String
& httpUserAgent
) { setHTTPHeaderField("User-Agent", httpUserAgent
); }
98 String
httpAccept() const { return httpHeaderField("Accept"); }
99 void setHTTPAccept(const String
& httpAccept
) { setHTTPHeaderField("Accept", httpAccept
); }
101 void setResponseContentDispositionEncodingFallbackArray(const String
& encoding1
, const String
& encoding2
= String(), const String
& encoding3
= String());
103 FormData
* httpBody() const;
104 void setHTTPBody(PassRefPtr
<FormData
> httpBody
);
106 bool allowHTTPCookies() const;
107 void setAllowHTTPCookies(bool allowHTTPCookies
);
109 bool isConditional() const;
112 // Used when ResourceRequest is initialized from a platform representation of the request
113 ResourceRequestBase()
114 : m_resourceRequestUpdated(false)
115 , m_platformRequestUpdated(true)
119 ResourceRequestBase(const KURL
& url
, ResourceRequestCachePolicy policy
)
121 , m_cachePolicy(policy
)
122 , m_timeoutInterval(unspecifiedTimeoutInterval
)
123 , m_httpMethod("GET")
124 , m_allowHTTPCookies(true)
125 , m_resourceRequestUpdated(true)
126 , m_platformRequestUpdated(false)
130 void updatePlatformRequest() const;
131 void updateResourceRequest() const;
135 ResourceRequestCachePolicy m_cachePolicy
;
136 double m_timeoutInterval
;
137 KURL m_mainDocumentURL
;
139 HTTPHeaderMap m_httpHeaderFields
;
140 Vector
<String
> m_responseContentDispositionEncodingFallbackArray
;
141 RefPtr
<FormData
> m_httpBody
;
142 bool m_allowHTTPCookies
;
143 mutable bool m_resourceRequestUpdated
;
144 mutable bool m_platformRequestUpdated
;
147 const ResourceRequest
& asResourceRequest() const;
150 bool equalIgnoringHeaderFields(const ResourceRequestBase
&, const ResourceRequestBase
&);
152 bool operator==(const ResourceRequestBase
&, const ResourceRequestBase
&);
153 inline bool operator!=(ResourceRequestBase
& a
, const ResourceRequestBase
& b
) { return !(a
== b
); }
155 struct CrossThreadResourceRequestData
{
158 ResourceRequestCachePolicy m_cachePolicy
;
159 double m_timeoutInterval
;
160 KURL m_mainDocumentURL
;
163 OwnPtr
<CrossThreadHTTPHeaderMapData
> m_httpHeaders
;
164 Vector
<String
> m_responseContentDispositionEncodingFallbackArray
;
165 RefPtr
<FormData
> m_httpBody
;
166 bool m_allowHTTPCookies
;
169 unsigned initializeMaximumHTTPConnectionCountPerHost();
171 } // namespace WebCore
173 #endif // ResourceRequestBase_h