public
Description: Three20 is an Objective-C library for iPhone developers
Homepage: http://groups.google.com/group/three20/
Clone URL: git://github.com/facebook/three20.git
three20 / src / Three20 / TTURLRequest.h
100644 199 lines (153 sloc) 5.066 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#import "Three20/TTGlobal.h"
 
@protocol TTURLRequestDelegate, TTURLResponse;
 
@interface TTURLRequest : NSObject {
  NSString* _URL;
  NSString* _httpMethod;
  NSData* _httpBody;
  NSMutableDictionary* _parameters;
  NSMutableDictionary* _headers;
  NSString* _contentType;
  NSMutableArray* _delegates;
  NSMutableArray* _files;
  id<TTURLResponse> _response;
  TTURLRequestCachePolicy _cachePolicy;
  NSTimeInterval _cacheExpirationAge;
  NSString* _cacheKey;
  NSDate* _timestamp;
  NSInteger _totalBytesLoaded;
  NSInteger _totalBytesExpected;
  id _userInfo;
  BOOL _isLoading;
  BOOL _shouldHandleCookies;
  BOOL _respondedFromCache;
  BOOL _filterPasswordLogging;
}
 
/**
* An object that receives messages about the progress of the request.
*/
@property(nonatomic,readonly) NSMutableArray* delegates;
 
/**
* An object that handles the response data and may parse and validate it.
*/
@property(nonatomic,retain) id<TTURLResponse> response;
 
/**
* The URL to be loaded by the request.
*/
@property(nonatomic,copy) NSString* URL;
 
/**
* The HTTP method to send with the request.
*/
@property(nonatomic,copy) NSString* httpMethod;
 
/**
* The HTTP body to send with the request.
*/
@property(nonatomic,retain) NSData* httpBody;
 
/**
* The content type of the data in the request.
*/
@property(nonatomic,copy) NSString* contentType;
 
/**
* Parameters to use for an HTTP post.
*/
@property(nonatomic,readonly) NSMutableDictionary* parameters;
 
/**
* Custom HTTP headers.
*/
@property(nonatomic,readonly) NSMutableDictionary* headers;
 
/**
* Defaults to "any".
*/
@property(nonatomic) TTURLRequestCachePolicy cachePolicy;
 
/**
* The maximum age of cached data that can be used as a response.
*/
@property(nonatomic) NSTimeInterval cacheExpirationAge;
 
@property(nonatomic,retain) NSString* cacheKey;
 
@property(nonatomic,retain) id userInfo;
 
@property(nonatomic,retain) NSDate* timestamp;
 
@property(nonatomic) BOOL isLoading;
 
@property(nonatomic) BOOL shouldHandleCookies;
 
@property(nonatomic) NSInteger totalBytesLoaded;
 
@property(nonatomic) NSInteger totalBytesExpected;
 
@property(nonatomic) BOOL respondedFromCache;
 
/**
* Whether parameters named "password" should be suppressed in log messages.
*/
@property(nonatomic,assign) BOOL filterPasswordLogging;
 
+ (TTURLRequest*)request;
 
+ (TTURLRequest*)requestWithURL:(NSString*)URL delegate:(id<TTURLRequestDelegate>)delegate;
 
- (id)initWithURL:(NSString*)URL delegate:(id<TTURLRequestDelegate>)delegate;
 
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
 
/**
* Adds a file whose data will be posted.
*/
- (void)addFile:(NSData*)data mimeType:(NSString*)mimeType fileName:(NSString*)fileName;
 
/**
* Attempts to send a request.
*
* If the request can be resolved by the cache, it will happen synchronously. Otherwise,
* the request will respond to its delegate asynchronously.
*
* @return YES if the request was loaded synchronously from the cache.
*/
- (BOOL)send;
 
/**
* Cancels the request.
*
* If there are multiple requests going to the same URL as this request, the others will
* not be cancelled.
*/
- (void)cancel;
 
- (NSURLRequest*)createNSURLRequest;
 
@end
 
///////////////////////////////////////////////////////////////////////////////////////////////////
 
@protocol TTURLRequestDelegate <NSObject>
 
@optional
 
/**
* The request has begun loading.
*/
- (void)requestDidStartLoad:(TTURLRequest*)request;
 
/**
* The request has loaded some more data.
*
* Check the totalBytesLoaded and totalBytesExpected properties for details.
*/
- (void)requestDidUploadData:(TTURLRequest*)request;
 
/**
* The request has loaded data has loaded and been processed into a response.
*
* If the request is served from the cache, this is the only delegate method that will be called.
*/
- (void)requestDidFinishLoad:(TTURLRequest*)request;
 
/**
*
*/
- (void)request:(TTURLRequest*)request didFailLoadWithError:(NSError*)error;
 
/**
*
*/
- (void)requestDidCancelLoad:(TTURLRequest*)request;
 
@end
 
///////////////////////////////////////////////////////////////////////////////////////////////////
 
/**
* A helper class for storing user info to help identify a request.
*
* This class lets you store both a strong reference and a weak reference for the duration of
* the request. The weak reference is special because TTURLRequestQueue will examine it when
* you call cancelRequestsWithDelegate to see if the weak object is the delegate in question.
* For this reason, this object is a safe way to store an object that may be destroyed before
* the request completes if you call cancelRequestsWithDelegate in the object's destructor.
*/
@interface TTUserInfo : NSObject {
  NSString* _topic;
  id _strong;
  id _weak;
}
 
@property(nonatomic,retain) NSString* topic;
@property(nonatomic,retain) id strong;
@property(nonatomic,assign) id weak;
 
+ (id)topic:(NSString*)topic strong:(id)strong weak:(id)weak;
+ (id)topic:(NSString*)topic;
+ (id)weak:(id)weak;
 
- (id)initWithTopic:(NSString*)topic strong:(id)strong weak:(id)weak;
 
@end