Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 265 lines (214 sloc) 7.081 kb
167eaa6 @jverkoey Use // instead of /** for license headers.
jverkoey authored
1 //
aebe4c1 @jverkoey Update the copyright.
jverkoey authored
2 // Copyright 2009-2010 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
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
25 @protocol TTURLRequestDelegate;
26 @protocol TTURLResponse;
9c6d6a2 @joehewitt First commit
joehewitt authored
27
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
28 /**
29 * The Three20 network request object, built to work with the Three20 cache and co.
30 *
31 * Allows customization of the http method, body, and parameters, as well as natural response
32 * processing using TTURLResponse objects.
33 */
6394c48 @joehewitt * Fixed bug @1026: Rename T3* to TT*
joehewitt authored
34 @interface TTURLRequest : NSObject {
f762dc7 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
35 NSString* _urlPath;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
36
37 NSString* _httpMethod;
38 NSData* _httpBody;
39 NSMutableDictionary* _parameters;
40 NSMutableDictionary* _headers;
41
42 NSString* _contentType;
43 NSStringEncoding _charsetForMultipart;
44
45 NSMutableArray* _files;
46
47 id<TTURLResponse> _response;
48
6394c48 @joehewitt * Fixed bug @1026: Rename T3* to TT*
joehewitt authored
49 TTURLRequestCachePolicy _cachePolicy;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
50 NSTimeInterval _cacheExpirationAge;
51 NSString* _cacheKey;
9c6d6a2 @joehewitt First commit
joehewitt authored
52
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
53 NSDate* _timestamp;
5a05691 @joehewitt Functionality of T3URLCache expanded and stabilized greatly
joehewitt authored
54
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
55 NSInteger _totalBytesLoaded;
56 NSInteger _totalBytesExpected;
0f95d8d @cemaleker [Network] Download tracking implemented
cemaleker authored
57
58 NSInteger _totalBytesDownloaded;
59 NSInteger _totalContentLength;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
60
61 id _userInfo;
62
63 BOOL _isLoading;
64 BOOL _shouldHandleCookies;
65 BOOL _respondedFromCache;
66 BOOL _filterPasswordLogging;
67
68 NSMutableArray* _delegates;
69 }
5a05691 @joehewitt Functionality of T3URLCache expanded and stabilized greatly
joehewitt authored
70
71 /**
f762dc7 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
72 * The URL path to be loaded by the request.
73 */
74 @property (nonatomic, copy) NSString* urlPath;
75
76 /**
77 * The URL path to be loaded by the request.
78 *
79 * Deprecated due to name ambiguity. Use urlPath instead.
80 * Remove after May 6, 2010.
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
81 */
f762dc7 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
82 @property (nonatomic, copy) NSString* URL __TTDEPRECATED_METHOD;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
83
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
84 /**
85 * The HTTP method to send with the request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
86 *
87 * @example @"POST"
88 * @example @"GET"
c05a31d @jverkoey [Dox] Document and clean up the PUT logic.
jverkoey authored
89 * @example @"PUT"
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
90 * @default nil (equivalent to @"GET")
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
91 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
92 @property (nonatomic, copy) NSString* httpMethod;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
93
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
94 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
95 * An object that handles the response data and may parse and validate it.
96 *
97 * @see TTURLDataResponse
98 * @see TTURLImageResponse
878913e @jverkoey [Network] Document TTURLRequest further.
jverkoey authored
99 * @see TTURLXMLResponse
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
100 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
101 @property (nonatomic, retain) id<TTURLResponse> response;
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
102
103 /**
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
104 * The HTTP body to send with the request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
105 *
c05a31d @jverkoey [Dox] Document and clean up the PUT logic.
jverkoey authored
106 * If provided, will always be used. Please consider this when using POST/PUT methods: if
107 * httpBody is provided, then the POST/PUT data generated from the parameters property will not
108 * be used.
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
109 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
110 @property (nonatomic, retain) NSData* httpBody;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
111
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
112 /**
113 * The content type of the data in the request.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
114 *
878913e @jverkoey [Network] Document TTURLRequest further.
jverkoey authored
115 * 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
116 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
117 @property (nonatomic, copy) NSString* contentType;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
118
119 /**
c05a31d @jverkoey [Dox] Document and clean up the PUT logic.
jverkoey authored
120 * Parameters to use for an HTTP POST/PUT.
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
121 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
122 @property (nonatomic, readonly) NSMutableDictionary* parameters;
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
123
124 /**
bcea055 @joehewitt * Merged patch from vergeguy to support custom HTTP headers in TTURLR…
joehewitt authored
125 * Custom HTTP headers.
126 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
127 @property (nonatomic, readonly) NSMutableDictionary* headers;
bcea055 @joehewitt * Merged patch from vergeguy to support custom HTTP headers in TTURLR…
joehewitt authored
128
129 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
130 * @default TTURLRequestCachePolicyDefault
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
131 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
132 @property (nonatomic) TTURLRequestCachePolicy cachePolicy;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
133
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
134 /**
135 * The maximum age of cached data that can be used as a response.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
136 *
137 * @default TT_DEFAULT_CACHE_EXPIRATION_AGE (1 week)
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
138 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
139 @property (nonatomic) NSTimeInterval cacheExpirationAge;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
140
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
141 /**
142 * 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
143 * 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
144 *
145 * By setting the cacheKey, you may override the default cache key generator with your own.
146 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
147 @property (nonatomic, retain) NSString* cacheKey;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
148
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
149 /**
150 * A dummy object used to uniquely identify this request object once it's been sent into the fray.
151 * Generally TTUserInfo objects are used here.
152 *
153 * @see TTUserInfo
154 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
155 @property (nonatomic, retain) id userInfo;
ff236ef @joehewitt * Expose cache method to get path of a cache key
joehewitt authored
156
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
157 @property (nonatomic, retain) NSDate* timestamp;
6eb7ec5 @joehewitt * Fixed bug @1047: Simply the request delegate model
joehewitt authored
158
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
159 /**
160 * Whether or not the request is currently active.
161 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
162 @property (nonatomic) BOOL isLoading;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
163
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
164 /**
165 * Decide whether default cookie handling will happen for this request.
166 *
167 * @param YES if cookies should be sent with and set for this request;
168 * otherwise NO.
169 * @discussion The default is YES - in other words, cookies are sent from and
170 * stored to the cookie manager by default.
171 *
172 * @default YES
173 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
174 @property (nonatomic) BOOL shouldHandleCookies;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
175
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
176 /**
177 * The number of bytes loaded by this request.
178 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
179 @property (nonatomic) NSInteger totalBytesLoaded;
9a99214 * Dispatch upload progress messages to TTURLRequest delegates (new fe…
Joe Hewitt authored
180
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
181 /**
182 * The number of expected bytes from this request.
183 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
184 @property (nonatomic) NSInteger totalBytesExpected;
9a99214 * Dispatch upload progress messages to TTURLRequest delegates (new fe…
Joe Hewitt authored
185
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
186 /**
0f95d8d @cemaleker [Network] Download tracking implemented
cemaleker authored
187 * The number of downloaded bytes from server.
188 */
189 @property (nonatomic) NSInteger totalBytesDownloaded;
190
191 /**
192 * The number of content length of request.
193 */
194 @property (nonatomic) NSInteger totalContentLength;
195
196 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
197 * Whether or not the request was loaded from the cache.
198 *
199 * This is only valid after the request has completed.
200 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
201 @property (nonatomic) BOOL respondedFromCache;
9c6d6a2 @joehewitt First commit
joehewitt authored
202
203ef35 * Add option to TTURLRequest to suppress logging of passwords
Owen Yamauchi authored
203 /**
204 * Whether parameters named "password" should be suppressed in log messages.
205 */
6c004f3 @jverkoey [Dox] Property style cleanup.
jverkoey authored
206 @property (nonatomic, assign) BOOL filterPasswordLogging;
203ef35 * Add option to TTURLRequest to suppress logging of passwords
Owen Yamauchi authored
207
d8a6787 Implement a way to set the character set for a multiform post.
Tobias Rundström authored
208 /**
209 * Charset to use when creating multipart/form-data data.
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
210 *
211 * @default NSUTF8StringEncoding to remain backwards compatible.
d8a6787 Implement a way to set the character set for a multiform post.
Tobias Rundström authored
212 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
213 @property (nonatomic) NSStringEncoding charsetForMultipart;
d8a6787 Implement a way to set the character set for a multiform post.
Tobias Rundström authored
214
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
215 /**
216 * An array of non-retained objects that receive messages about the progress of the request.
217 */
d456049 @jverkoey [Dox] Clean up TTURLRequest.
jverkoey authored
218 @property (nonatomic, readonly) NSMutableArray* delegates;
219
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
220
6394c48 @joehewitt * Fixed bug @1026: Rename T3* to TT*
joehewitt authored
221 + (TTURLRequest*)request;
8ecc4b4 @joehewitt Improve robustness of photo viewer
joehewitt authored
222
cf8d192 @jverkoey TTURLRequestDelegate is now a recommended delegate of TTURLRequest.
jverkoey authored
223 + (TTURLRequest*)requestWithURL:(NSString*)URL delegate:(id /*<TTURLRequestDelegate>*/)delegate;
9c6d6a2 @joehewitt First commit
joehewitt authored
224
cf8d192 @jverkoey TTURLRequestDelegate is now a recommended delegate of TTURLRequest.
jverkoey authored
225 - (id)initWithURL:(NSString*)URL delegate:(id /*<TTURLRequestDelegate>*/)delegate;
9c6d6a2 @joehewitt First commit
joehewitt authored
226
bcea055 @joehewitt * Merged patch from vergeguy to support custom HTTP headers in TTURLR…
joehewitt authored
227 - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
228
9c6d6a2 @joehewitt First commit
joehewitt authored
229 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
230 * Add a file whose data will be posted.
b9f99c0 @joehewitt * Support for including files to post with TTURLRequest (useful for u…
joehewitt authored
231 */
232 - (void)addFile:(NSData*)data mimeType:(NSString*)mimeType fileName:(NSString*)fileName;
233
234 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
235 * Attempt to send a request.
37a2ad2 @joehewitt Some re-factoring to support migrating to T3ImageView in Facebook
joehewitt authored
236 *
237 * If the request can be resolved by the cache, it will happen synchronously. Otherwise,
238 * the request will respond to its delegate asynchronously.
239 *
9c6d6a2 @joehewitt First commit
joehewitt authored
240 * @return YES if the request was loaded synchronously from the cache.
241 */
242 - (BOOL)send;
243
37a2ad2 @joehewitt Some re-factoring to support migrating to T3ImageView in Facebook
joehewitt authored
244 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
245 * Attempt to send a synchronous request.
1404c7b @jverkoey Add a synchronous request implementation to TTURLRequest.
jverkoey authored
246 *
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
247 * 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
248 * the network or from the cache.
249 *
250 * @return YES if the request was loaded from the cache.
251 */
252 - (BOOL)sendSynchronously;
253
254 /**
efb0236 @jverkoey [Dox] Document TTURLRequest.
jverkoey authored
255 * Cancel the request.
37a2ad2 @joehewitt Some re-factoring to support migrating to T3ImageView in Facebook
joehewitt authored
256 *
257 * If there are multiple requests going to the same URL as this request, the others will
258 * not be cancelled.
259 */
9c6d6a2 @joehewitt First commit
joehewitt authored
260 - (void)cancel;
261
b5e86f3 @joehewitt * Method to create an NSURLRequest from a TTURLRequest
joehewitt authored
262 - (NSURLRequest*)createNSURLRequest;
263
9c6d6a2 @joehewitt First commit
joehewitt authored
264 @end
Something went wrong with that request. Please try again.