Skip to content

HTTPS clone URL

Subversion checkout URL

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