forked from lukhnos/objectiveflickr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLFHTTPRequest.h
More file actions
163 lines (137 loc) · 6.1 KB
/
LFHTTPRequest.h
File metadata and controls
163 lines (137 loc) · 6.1 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
//
// LFHTTPRequest.h
//
// Copyright (c) 2007-2009 Lithoglyph Inc. (http://lithoglyph.com)
// Copyright (c) 2007-2009 Lukhnos D. Liu (http://lukhnos.org)
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
#import <CoreFoundation/CoreFoundation.h>
#import <CFNetwork/CFNetwork.h>
#import <CFNetwork/CFProxySupport.h>
#endif
extern NSString *const LFHTTPRequestConnectionError;
extern NSString *const LFHTTPRequestTimeoutError;
extern const NSTimeInterval LFHTTPRequestDefaultTimeoutInterval;
extern NSString *const LFHTTPRequestWWWFormURLEncodedContentType;
extern NSString *const LFHTTPRequestGETMethod;
extern NSString *const LFHTTPRequestHEADMethod;
extern NSString *const LFHTTPRequestPOSTMethod;
@interface LFHTTPRequest : NSObject
{
id _delegate;
NSTimeInterval _timeoutInterval;
NSString *_userAgent;
NSString *_contentType;
NSDictionary *_requestHeader;
NSMutableData *_receivedData;
NSString *_receivedContentType;
CFReadStreamRef _readStream;
NSTimer *_receivedDataTracker;
NSTimeInterval _lastReceivedDataUpdateTime;
NSTimer *_requestMessageBodyTracker;
NSTimeInterval _lastSentDataUpdateTime;
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
NSUInteger _requestMessageBodySize;
NSUInteger _expectedDataLength;
NSUInteger _lastReceivedBytes;
NSUInteger _lastSentBytes;
#else
unsigned int _requestMessageBodySize;
unsigned int _expectedDataLength;
unsigned int _lastReceivedBytes;
unsigned int _lastSentBytes;
#endif
void *_readBuffer;
size_t _readBufferSize;
id _sessionInfo;
BOOL _shouldWaitUntilDone;
NSMessagePort *_synchronousMessagePort;
}
- (id)init;
- (BOOL)isRunning;
- (void)cancel;
- (void)cancelWithoutDelegateMessage;
- (BOOL)shouldWaitUntilDone;
- (void)setShouldWaitUntilDone:(BOOL)waitUntilDone;
- (BOOL)performMethod:(NSString *)methodName onURL:(NSURL *)url withData:(NSData *)data;
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
- (BOOL)performMethod:(NSString *)methodName onURL:(NSURL *)url withInputStream:(NSInputStream *)inputStream knownContentSize:(NSUInteger)byteStreamSize;
#else
- (BOOL)performMethod:(NSString *)methodName onURL:(NSURL *)url withInputStream:(NSInputStream *)inputStream knownContentSize:(unsigned int)byteStreamSize;
#endif
- (NSData *)getReceivedDataAndDetachFromRequest;
- (NSTimeInterval)timeoutInterval;
- (void)setTimeoutInterval:(NSTimeInterval)timeoutInterval;
- (NSData *)receivedData;
- (NSString *)receivedContentType;
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
- (NSUInteger)expectedDataLength;
#else
- (unsigned int)expectedDataLength;
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
@property (copy) NSDictionary *requestHeader;
@property (assign) NSTimeInterval timeoutInterval;
@property (copy) NSString *userAgent;
@property (copy) NSString *contentType;
@property (readonly) NSData *receivedData;
@property (readonly) NSUInteger expectedDataLength;
@property (assign) id delegate;
@property (retain) id sessionInfo;
@property (assign) BOOL shouldWaitUntilDone;
@property (readonly) BOOL isRunning;
#else
- (NSDictionary *)requestHeader;
- (void)setRequestHeader:(NSDictionary *)requestHeader;
- (NSString *)userAgent;
- (void)setUserAgent:(NSString *)userAgent;
- (NSString *)contentType;
- (void)setContentType:(NSString *)contentType;
- (id)delegate;
- (void)setDelegate:(id)delegate;
- (void)setSessionInfo:(id)aSessionInfo;
- (id)sessionInfo;
#endif
@end
@interface NSObject (LFHTTPRequestDelegate)
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
- (void)httpRequest:(LFHTTPRequest *)request didReceiveStatusCode:(NSUInteger)statusCode URL:(NSURL *)url responseHeader:(CFHTTPMessageRef)header;
- (void)httpRequestDidComplete:(LFHTTPRequest *)request;
- (void)httpRequestDidCancel:(LFHTTPRequest *)request;
- (void)httpRequest:(LFHTTPRequest *)request didFailWithError:(NSString *)error;
- (void)httpRequest:(LFHTTPRequest *)request receivedBytes:(NSUInteger)bytesReceived expectedTotal:(NSUInteger)total;
- (void)httpRequest:(LFHTTPRequest *)request sentBytes:(NSUInteger)bytesSent total:(NSUInteger)total;
// note if you implemented this, the data is never written to the receivedData of the HTTP request instance
- (void)httpRequest:(LFHTTPRequest *)request writeReceivedBytes:(void *)bytes size:(NSUInteger)blockSize expectedTotal:(NSUInteger)total;
#else
- (void)httpRequest:(LFHTTPRequest *)request didReceiveStatusCode:(unsigned int)statusCode URL:(NSURL *)url responseHeader:(CFHTTPMessageRef)header;
- (void)httpRequestDidComplete:(LFHTTPRequest *)request;
- (void)httpRequestDidCancel:(LFHTTPRequest *)request;
- (void)httpRequest:(LFHTTPRequest *)request didFailWithError:(NSString *)error;
- (void)httpRequest:(LFHTTPRequest *)request receivedBytes:(unsigned int)bytesReceived expectedTotal:(unsigned int)total;
- (void)httpRequest:(LFHTTPRequest *)request sentBytes:(unsigned int)bytesSent total:(unsigned int)total;
- (void)httpRequest:(LFHTTPRequest *)request writeReceivedBytes:(void *)bytes size:(unsigned int)blockSize expectedTotal:(unsigned int)total;
#endif
@end