Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 304 lines (250 sloc) 8.572 kb
167eaa6 @jverkoey Use // instead of /** for license headers.
jverkoey authored
1 //
23b3258 @jwang Massive Copyright Notice Update
jwang authored
2 // Copyright 2009-2011 Facebook
167eaa6 @jverkoey Use // instead of /** for license headers.
jverkoey authored
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
58ebed0 @jverkoey Prepend the Apache license to every file.
jverkoey authored
16
800bc03 @jverkoey [Network] Move TTURLRequestCachePolicy to a separate file.
jverkoey authored
17 #import <Foundation/Foundation.h>
18
6471488 @jverkoey [Dox] General cleanup of Network. Consistent include groups.
jverkoey authored
19 // Network
27eefd1 @jverkoey Update header paths and add the Three20Network project configuration.
jverkoey authored
20 #import "Three20Network/TTURLRequestCachePolicy.h"
9c6d6a2 @joehewitt First commit
joehewitt authored
21
6471488 @jverkoey [Dox] General cleanup of Network. Consistent include groups.
jverkoey authored
22 // Core
27eefd1 @jverkoey Update header paths and add the Three20Network project configuration.
jverkoey authored
23 #import "Three20Core/TTCorePreprocessorMacros.h" // For __TTDEPRECATED_METHOD
f762dc7 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
24
fff1d14 @jwang Squashed commit of the following:
jwang authored
25 /**
26 * A constant to improve code readabillity, when using negative numbers for
27 * timeoutInterval.
28 *
29 * @see timeoutInterval
30 */
31 extern const NSTimeInterval TTURLRequestUseQueueTimeout;
32
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
33 @protocol TTURLRequestDelegate;
34 @protocol TTURLResponse;
9c6d6a2 @joehewitt First commit
joehewitt authored
35
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
36 /**
37 * The Three20 network request object, built to work with the Three20 cache and co.
38 *
39 * Allows customization of the http method, body, and parameters, as well as natural response
40 * processing using TTURLResponse objects.
41 */
6394c48 @joehewitt * Fixed bug @1026: Rename T3* to TT*
joehewitt authored
42 @interface TTURLRequest : NSObject {
f762dc7 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
43 NSString* _urlPath;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
44
45 NSString* _httpMethod;
46 NSData* _httpBody;
47 NSMutableDictionary* _parameters;
48 NSMutableDictionary* _headers;
49
50 NSString* _contentType;
51 NSStringEncoding _charsetForMultipart;
52
53 NSMutableArray* _files;
54
55 id<TTURLResponse> _response;
56
6394c48 @joehewitt * Fixed bug @1026: Rename T3* to TT*
joehewitt authored
57 TTURLRequestCachePolicy _cachePolicy;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
58 NSTimeInterval _cacheExpirationAge;
59 NSString* _cacheKey;
9c6d6a2 @joehewitt First commit
joehewitt authored
60
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
61 NSDate* _timestamp;
5a05691 @joehewitt Functionality of T3URLCache expanded and stabilized greatly
joehewitt authored
62
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
63 NSInteger _totalBytesLoaded;
64 NSInteger _totalBytesExpected;
fff1d14 @jwang Squashed commit of the following:
jwang authored
65
66 NSTimeInterval _timeoutInterval;
8464e20 @jverkoey [delint] Delint the entire project.
jverkoey authored
67
0f95d8d @cemaleker [Network] Download tracking implemented
cemaleker authored
68 NSInteger _totalBytesDownloaded;
69 NSInteger _totalContentLength;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
70
71 id _userInfo;
72
73 BOOL _isLoading;
74 BOOL _shouldHandleCookies;
75 BOOL _respondedFromCache;
76 BOOL _filterPasswordLogging;
77
78 NSMutableArray* _delegates;
79 }
5a05691 @joehewitt Functionality of T3URLCache expanded and stabilized greatly
joehewitt authored
80
81 /**
f762dc7 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
82 * The URL path to be loaded by the request.
83 */
84 @property (nonatomic, copy) NSString* urlPath;
85
86 /**
87 * The URL path to be loaded by the request.
88 *
89 * Deprecated due to name ambiguity. Use urlPath instead.
90 * Remove after May 6, 2010.
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
91 */
f762dc7 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
92 @property (nonatomic, copy) NSString* URL __TTDEPRECATED_METHOD;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
93
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
94 /**
95 * The HTTP method to send with the request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
96 *
97 * @example @"POST"
98 * @example @"GET"
c05a31d @jverkoey [Dox] Document and clean up the PUT logic.
jverkoey authored
99 * @example @"PUT"
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
100 * @default nil (equivalent to @"GET")
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
101 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
102 @property (nonatomic, copy) NSString* httpMethod;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
103
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
104 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
105 * An object that handles the response data and may parse and validate it.
106 *
107 * @see TTURLDataResponse
108 * @see TTURLImageResponse
878913e @jverkoey [Network] Document TTURLRequest further.
jverkoey authored
109 * @see TTURLXMLResponse
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
110 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
111 @property (nonatomic, retain) id<TTURLResponse> response;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
112
113 /**
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
114 * The HTTP body to send with the request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
115 *
c05a31d @jverkoey [Dox] Document and clean up the PUT logic.
jverkoey authored
116 * If provided, will always be used. Please consider this when using POST/PUT methods: if
117 * httpBody is provided, then the POST/PUT data generated from the parameters property will not
118 * be used.
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
119 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
120 @property (nonatomic, retain) NSData* httpBody;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
121
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
122 /**
123 * The content type of the data in the request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
124 *
878913e @jverkoey [Network] Document TTURLRequest further.
jverkoey authored
125 * If not provided and httpMethod is POST/PUT, then contentType is @"multipart/form-data".
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
126 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
127 @property (nonatomic, copy) NSString* contentType;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
128
129 /**
c05a31d @jverkoey [Dox] Document and clean up the PUT logic.
jverkoey authored
130 * Parameters to use for an HTTP POST/PUT.
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
131 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
132 @property (nonatomic, readonly) NSMutableDictionary* parameters;
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
133
134 /**
bcea055 @joehewitt * Merged patch from vergeguy to support custom HTTP headers in TTURLRequ...
joehewitt authored
135 * Custom HTTP headers.
136 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
137 @property (nonatomic, readonly) NSMutableDictionary* headers;
bcea055 @joehewitt * Merged patch from vergeguy to support custom HTTP headers in TTURLRequ...
joehewitt authored
138
139 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
140 * @default TTURLRequestCachePolicyDefault
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
141 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
142 @property (nonatomic) TTURLRequestCachePolicy cachePolicy;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
143
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
144 /**
145 * The maximum age of cached data that can be used as a response.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
146 *
147 * @default TT_DEFAULT_CACHE_EXPIRATION_AGE (1 week)
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
148 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
149 @property (nonatomic) NSTimeInterval cacheExpirationAge;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
150
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
151 /**
152 * If no cache key is provided, a unique key is generated from the request data. If the request
c05a31d @jverkoey [Dox] Document and clean up the PUT logic.
jverkoey authored
153 * is a POST/PUT request, then the POST/PUT parameters are also used to generate the cache key.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
154 *
155 * By setting the cacheKey, you may override the default cache key generator with your own.
156 */
8464e20 @jverkoey [delint] Delint the entire project.
jverkoey authored
157 @property (nonatomic, copy) NSString* cacheKey;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
158
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
159 /**
160 * A dummy object used to uniquely identify this request object once it's been sent into the fray.
161 * Generally TTUserInfo objects are used here.
162 *
163 * @see TTUserInfo
164 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
165 @property (nonatomic, retain) id userInfo;
ff236ef @joehewitt * Expose cache method to get path of a cache key
joehewitt authored
166
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
167 @property (nonatomic, retain) NSDate* timestamp;
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
168
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
169 /**
170 * Whether or not the request is currently active.
171 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
172 @property (nonatomic) BOOL isLoading;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
173
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
174 /**
175 * Decide whether default cookie handling will happen for this request.
176 *
177 * @param YES if cookies should be sent with and set for this request;
178 * otherwise NO.
179 * @discussion The default is YES - in other words, cookies are sent from and
180 * stored to the cookie manager by default.
181 *
182 * @default YES
183 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
184 @property (nonatomic) BOOL shouldHandleCookies;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
185
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
186 /**
641856e @tonklon [Dox] small clearification
tonklon authored
187 * The number of request body bytes already uploaded by this request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
188 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
189 @property (nonatomic) NSInteger totalBytesLoaded;
9a99214 * Dispatch upload progress messages to TTURLRequest delegates (new featu...
Joe Hewitt authored
190
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
191 /**
641856e @tonklon [Dox] small clearification
tonklon authored
192 * The total number of request body bytes expected to be uploaded for this request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
193 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
194 @property (nonatomic) NSInteger totalBytesExpected;
9a99214 * Dispatch upload progress messages to TTURLRequest delegates (new featu...
Joe Hewitt authored
195
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
196 /**
0f95d8d @cemaleker [Network] Download tracking implemented
cemaleker authored
197 * The number of downloaded bytes from server.
198 */
199 @property (nonatomic) NSInteger totalBytesDownloaded;
200
201 /**
202 * The number of content length of request.
203 */
204 @property (nonatomic) NSInteger totalContentLength;
205
206 /**
fff1d14 @jwang Squashed commit of the following:
jwang authored
207 * The timeout to use for the request.
208 *
209 * If a negative value is set the request uses
210 * the defaultTimeout of the TTURLRequestQueue. <b>This differs from behaviour of
211 * NSURLRequest.</b> Given a negative timeoutInterval NSURLRequest always fails.
212 *
213 * You should use the TTURLRequestUseQueueTimeout constant to improve
214 * code readabillity, instead of negative numbers.
215 *
216 * The default value is TTURLRequestUseQueueTimeout
217 *
218 * @par from NSURLRequest.h:
219 *
220 * The timeout interval specifies the limit on the idle
221 * interval alloted to a request in the process of loading. The "idle
222 * interval" is defined as the period of time that has passed since the
223 * last instance of load activity occurred for a request that is in the
224 * process of loading. Hence, when an instance of load activity occurs
225 * (e.g. bytes are received from the network for a request), the idle
226 * interval for a request is reset to 0. If the idle interval ever
227 * becomes greater than or equal to the timeout interval, the request
228 * is considered to have timed out. This timeout interval is measured
229 * in seconds.
230 *
231 * @see TTURLRequestQueue::defaultTimeout
232 */
233 @property (nonatomic) NSTimeInterval timeoutInterval;
234
235 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
236 * Whether or not the request was loaded from the cache.
237 *
238 * This is only valid after the request has completed.
239 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
240 @property (nonatomic) BOOL respondedFromCache;
9c6d6a2 @joehewitt First commit
joehewitt authored
241
203ef35 * Add option to TTURLRequest to suppress logging of passwords
Owen Yamauchi authored
242 /**
243 * Whether parameters named "password" should be suppressed in log messages.
244 */
6c004f3 @jverkoey [Dox] Property style cleanup.
jverkoey authored
245 @property (nonatomic, assign) BOOL filterPasswordLogging;
203ef35 * Add option to TTURLRequest to suppress logging of passwords
Owen Yamauchi authored
246
d8a6787 Implement a way to set the character set for a multiform post.
Tobias Rundström authored
247 /**
248 * Charset to use when creating multipart/form-data data.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
249 *
250 * @default NSUTF8StringEncoding to remain backwards compatible.
d8a6787 Implement a way to set the character set for a multiform post.
Tobias Rundström authored
251 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
252 @property (nonatomic) NSStringEncoding charsetForMultipart;
d8a6787 Implement a way to set the character set for a multiform post.
Tobias Rundström authored
253
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
254 /**
255 * An array of non-retained objects that receive messages about the progress of the request.
256 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
257 @property (nonatomic, readonly) NSMutableArray* delegates;
258
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
259
6394c48 @joehewitt * Fixed bug @1026: Rename T3* to TT*
joehewitt authored
260 + (TTURLRequest*)request;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
261
cf8d192 @jverkoey TTURLRequestDelegate is now a recommended delegate of TTURLRequest.
jverkoey authored
262 + (TTURLRequest*)requestWithURL:(NSString*)URL delegate:(id /*<TTURLRequestDelegate>*/)delegate;
9c6d6a2 @joehewitt First commit
joehewitt authored
263
cf8d192 @jverkoey TTURLRequestDelegate is now a recommended delegate of TTURLRequest.
jverkoey authored
264 - (id)initWithURL:(NSString*)URL delegate:(id /*<TTURLRequestDelegate>*/)delegate;
9c6d6a2 @joehewitt First commit
joehewitt authored
265
bcea055 @joehewitt * Merged patch from vergeguy to support custom HTTP headers in TTURLRequ...
joehewitt authored
266 - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
267
9c6d6a2 @joehewitt First commit
joehewitt authored
268 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
269 * Add a file whose data will be posted.
b9f99c0 @joehewitt * Support for including files to post with TTURLRequest (useful for uplo...
joehewitt authored
270 */
271 - (void)addFile:(NSData*)data mimeType:(NSString*)mimeType fileName:(NSString*)fileName;
272
273 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
274 * Attempt to send a request.
37a2ad2 @joehewitt Some re-factoring to support migrating to T3ImageView in Facebook
joehewitt authored
275 *
276 * If the request can be resolved by the cache, it will happen synchronously. Otherwise,
277 * the request will respond to its delegate asynchronously.
278 *
9c6d6a2 @joehewitt First commit
joehewitt authored
279 * @return YES if the request was loaded synchronously from the cache.
280 */
281 - (BOOL)send;
282
37a2ad2 @joehewitt Some re-factoring to support migrating to T3ImageView in Facebook
joehewitt authored
283 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
284 * Attempt to send a synchronous request.
1404c7b @jverkoey Add a synchronous request implementation to TTURLRequest.
jverkoey authored
285 *
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
286 * The request will happen synchronously, regardless of whether the data is being grabbed from
1404c7b @jverkoey Add a synchronous request implementation to TTURLRequest.
jverkoey authored
287 * the network or from the cache.
288 *
289 * @return YES if the request was loaded from the cache.
290 */
291 - (BOOL)sendSynchronously;
292
293 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
294 * Cancel the request.
37a2ad2 @joehewitt Some re-factoring to support migrating to T3ImageView in Facebook
joehewitt authored
295 *
296 * If there are multiple requests going to the same URL as this request, the others will
297 * not be cancelled.
298 */
9c6d6a2 @joehewitt First commit
joehewitt authored
299 - (void)cancel;
300
b5e86f3 @joehewitt * Method to create an NSURLRequest from a TTURLRequest
joehewitt authored
301 - (NSURLRequest*)createNSURLRequest;
302
9c6d6a2 @joehewitt First commit
joehewitt authored
303 @end
Something went wrong with that request. Please try again.