ObjFW
 All Classes Functions Variables
OFHTTPRequest.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 
19 @class OFString;
20 @class OFDictionary;
21 @class OFURL;
22 @class OFHTTPRequest;
23 @class OFHTTPRequestResult;
24 @class OFTCPSocket;
25 @class OFDataArray;
26 
27 typedef enum of_http_request_type_t {
28  OF_HTTP_REQUEST_TYPE_GET,
29  OF_HTTP_REQUEST_TYPE_POST,
30  OF_HTTP_REQUEST_TYPE_HEAD
31 } of_http_request_type_t;
32 
36 #ifndef OF_HTTP_REQUEST_M
38 #else
39 @protocol OFHTTPRequestDelegate
40 #endif
41 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
42 @optional
43 #endif
44 
55 - (void)request: (OFHTTPRequest*)request
56  didCreateSocket: (OFTCPSocket*)socket;
57 
65 - (void)request: (OFHTTPRequest*)request
66  didReceiveHeaders: (OFDictionary*)headers
67  withStatusCode: (int)statusCode;
68 
78 - (void)request: (OFHTTPRequest*)request
79  didReceiveData: (const char*)data
80  withLength: (size_t)length;
81 
99 - (BOOL)request: (OFHTTPRequest*)request
100  willFollowRedirectTo: (OFURL*)URL;
101 @end
102 
107 {
108  OFURL *URL;
109  of_http_request_type_t requestType;
113  id <OFHTTPRequestDelegate> delegate;
114  BOOL storesData;
115 }
116 
117 #ifdef OF_HAVE_PROPERTIES
118 @property (copy) OFURL *URL;
119 @property of_http_request_type_t requestType;
120 @property (copy) OFString *queryString;
121 @property (copy) OFDictionary *headers;
122 @property BOOL redirectsFromHTTPSToHTTPAllowed;
123 @property (assign) id <OFHTTPRequestDelegate> delegate;
124 @property BOOL storesData;
125 #endif
126 
132 + (instancetype)request;
133 
140 + (instancetype)requestWithURL: (OFURL*)URL;
141 
148 - initWithURL: (OFURL*)URL;
149 
155 - (void)setURL: (OFURL*)URL;
156 
162 - (OFURL*)URL;
163 
169 - (void)setRequestType: (of_http_request_type_t)requestType;
170 
176 - (of_http_request_type_t)requestType;
177 
183 - (void)setQueryString: (OFString*)queryString;
184 
190 - (OFString*)queryString;
191 
197 - (void)setHeaders: (OFDictionary*)headers;
198 
204 - (OFDictionary*)headers;
205 
211 - (void)setRedirectsFromHTTPSToHTTPAllowed: (BOOL)allowed;
212 
218 - (BOOL)redirectsFromHTTPSToHTTPAllowed;
219 
225 - (void)setDelegate: (id <OFHTTPRequestDelegate>)delegate;
226 
232 - (id <OFHTTPRequestDelegate>)delegate;
233 
242 - (void)setStoresData: (BOOL)storesData;
243 
249 - (BOOL)storesData;
250 
256 - (OFHTTPRequestResult*)perform;
257 
266 - (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects;
267 @end
268 
273 {
274  short statusCode;
275  OFDataArray *data;
277 }
278 
279 #ifdef OF_HAVE_PROPERTIES
280 @property (readonly) short statusCode;
281 @property (readonly, copy) OFDictionary *headers;
282 @property (readonly, retain) OFDataArray *data;
283 #endif
284 
285 - initWithStatusCode: (short)status
286  headers: (OFDictionary*)headers
287  data: (OFDataArray*)data;
288 
294 - (short)statusCode;
295 
301 - (OFDictionary*)headers;
302 
310 - (OFDataArray*)data;
311 @end
312 
313 @interface OFObject (OFHTTPRequestDelegate) <OFHTTPRequestDelegate>
314 @end
315 
316 extern Class of_http_request_tls_socket_class;