ObjFW
src/OFHTTPRequest.h
00001 /*
00002  * Copyright (c) 2008, 2009, 2010, 2011, 2012
00003  *   Jonathan Schleifer <js@webkeks.org>
00004  *
00005  * All rights reserved.
00006  *
00007  * This file is part of ObjFW. It may be distributed under the terms of the
00008  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
00009  * the packaging of this file.
00010  *
00011  * Alternatively, it may be distributed under the terms of the GNU General
00012  * Public License, either version 2 or 3, which can be found in the file
00013  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
00014  * file.
00015  */
00016 
00017 #import "OFObject.h"
00018 
00019 @class OFString;
00020 @class OFDictionary;
00021 @class OFURL;
00022 @class OFHTTPRequest;
00023 @class OFHTTPRequestResult;
00024 @class OFTCPSocket;
00025 @class OFDataArray;
00026 
00027 typedef enum of_http_request_type_t {
00028         OF_HTTP_REQUEST_TYPE_GET,
00029         OF_HTTP_REQUEST_TYPE_POST,
00030         OF_HTTP_REQUEST_TYPE_HEAD
00031 } of_http_request_type_t;
00032 
00036 #ifndef OF_HTTP_REQUEST_M
00037 @protocol OFHTTPRequestDelegate <OFObject>
00038 #else
00039 @protocol OFHTTPRequestDelegate
00040 #endif
00041 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
00042 @optional
00043 #endif
00044 
00055 -   (void)request: (OFHTTPRequest*)request
00056   didCreateSocket: (OFTCPSocket*)socket;
00057 
00065 -     (void)request: (OFHTTPRequest*)request
00066   didReceiveHeaders: (OFDictionary*)headers
00067      withStatusCode: (int)statusCode;
00068 
00078 -  (void)request: (OFHTTPRequest*)request
00079   didReceiveData: (const char*)data
00080       withLength: (size_t)length;
00081 
00099 -        (BOOL)request: (OFHTTPRequest*)request
00100   willFollowRedirectTo: (OFURL*)URL;
00101 @end
00102 
00106 @interface OFHTTPRequest: OFObject
00107 {
00108         OFURL *URL;
00109         of_http_request_type_t requestType;
00110         OFString *queryString;
00111         OFDictionary *headers;
00112         BOOL redirectsFromHTTPSToHTTPAllowed;
00113         id <OFHTTPRequestDelegate> delegate;
00114         BOOL storesData;
00115 }
00116 
00117 #ifdef OF_HAVE_PROPERTIES
00118 @property (copy) OFURL *URL;
00119 @property of_http_request_type_t requestType;
00120 @property (copy) OFString *queryString;
00121 @property (copy) OFDictionary *headers;
00122 @property BOOL redirectsFromHTTPSToHTTPAllowed;
00123 @property (assign) id <OFHTTPRequestDelegate> delegate;
00124 @property BOOL storesData;
00125 #endif
00126 
00132 + request;
00133 
00140 + requestWithURL: (OFURL*)URL;
00141 
00148 - initWithURL: (OFURL*)URL;
00149 
00155 - (void)setURL: (OFURL*)URL;
00156 
00162 - (OFURL*)URL;
00163 
00169 - (void)setRequestType: (of_http_request_type_t)requestType;
00170 
00176 - (of_http_request_type_t)requestType;
00177 
00183 - (void)setQueryString: (OFString*)queryString;
00184 
00190 - (OFString*)queryString;
00191 
00197 - (void)setHeaders: (OFDictionary*)headers;
00198 
00204 - (OFDictionary*)headers;
00205 
00211 - (void)setRedirectsFromHTTPSToHTTPAllowed: (BOOL)allowed;
00212 
00218 - (BOOL)redirectsFromHTTPSToHTTPAllowed;
00219 
00225 - (void)setDelegate: (id <OFHTTPRequestDelegate>)delegate;
00226 
00232 - (id <OFHTTPRequestDelegate>)delegate;
00233 
00242 - (void)setStoresData: (BOOL)storesData;
00243 
00249 - (BOOL)storesData;
00250 
00256 - (OFHTTPRequestResult*)perform;
00257 
00266 - (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects;
00267 @end
00268 
00272 @interface OFHTTPRequestResult: OFObject
00273 {
00274         short statusCode;
00275         OFDataArray *data;
00276         OFDictionary *headers;
00277 }
00278 
00279 #ifdef OF_HAVE_PROPERTIES
00280 @property (readonly) short statusCode;
00281 @property (readonly, copy) OFDictionary *headers;
00282 @property (readonly, retain) OFDataArray *data;
00283 #endif
00284 
00286 - initWithStatusCode: (short)status
00287              headers: (OFDictionary*)headers
00288                 data: (OFDataArray*)data;
00290 
00296 - (short)statusCode;
00297 
00303 - (OFDictionary*)headers;
00304 
00312 - (OFDataArray*)data;
00313 @end
00314 
00315 @interface OFObject (OFHTTPRequestDelegate) <OFHTTPRequestDelegate>
00316 @end
00317 
00318 extern Class of_http_request_tls_socket_class;
 All Classes Functions Variables Properties