ObjFW
OFHTTPRequest.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
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 #import "OFString.h"
19 
20 #ifndef OF_HAVE_SOCKETS
21 # error No sockets available!
22 #endif
23 
24 OF_ASSUME_NONNULL_BEGIN
25 
26 @class OFURL;
27 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
28 @class OFDataArray;
29 @class OFString;
30 
36 typedef enum {
54 
61 typedef struct {
63  uint8_t major;
65  uint8_t minor;
67 
74 {
75  OFURL *_URL;
77  of_http_request_protocol_version_t _protocolVersion;
78  OFDictionary OF_GENERIC(OFString*, OFString*) *_headers;
79  OFDataArray *_body;
80  OFString *_remoteAddress;
81 }
82 
83 #ifdef OF_HAVE_PROPERTIES
84 @property (copy) OFURL *URL;
85 @property of_http_request_method_t method;
86 @property of_http_request_protocol_version_t protocolVersion;
87 @property OF_NULLABLE_PROPERTY (copy)
88  OFDictionary OF_GENERIC(OFString*, OFString*) *headers;
89 @property OF_NULLABLE_PROPERTY (retain) OFDataArray *body;
90 @property OF_NULLABLE_PROPERTY (copy) OFString *remoteAddress;
91 #endif
92 
98 + (instancetype)request;
99 
106 + (instancetype)requestWithURL: (OFURL*)URL;
107 
114 - initWithURL: (OFURL*)URL;
115 
121 - (void)setURL: (OFURL*)URL;
122 
128 - (OFURL*)URL;
129 
135 - (void)setMethod: (of_http_request_method_t)method;
136 
142 - (of_http_request_method_t)method;
143 
149 - (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion;
150 
156 - (of_http_request_protocol_version_t)protocolVersion;
157 
164 - (void)setProtocolVersionFromString: (OFString*)string;
165 
171 - (OFString*)protocolVersionString;
172 
178 - (void)setHeaders:
179  (nullable OFDictionary OF_GENERIC(OFString*, OFString*)*)headers;
180 
186 - (nullable OFDictionary OF_GENERIC(OFString*, OFString*)*)headers;
187 
193 - (void)setBody: (nullable OFDataArray*)body;
194 
201 - (void)setBodyFromString: (nullable OFString*)string;
202 
210 - (void)setBodyFromString: (nullable OFString*)string
211  encoding: (of_string_encoding_t)encoding;
212 
218 - (nullable OFDataArray*)body;
219 
225 - (void)setRemoteAddress: (nullable OFString*)remoteAddress;
226 
232 - (nullable OFString*)remoteAddress;
233 @end
234 
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 
244 extern const char *OF_NULLABLE of_http_request_method_to_string(
245  of_http_request_method_t method);
246 
254  const char *string);
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 OF_ASSUME_NONNULL_END
Definition: OFHTTPRequest.h:46
Definition: OFHTTPRequest.h:38
const char *OF_NULLABLE of_http_request_method_to_string(of_http_request_method_t method)
Returns a C string describing the specified request method.
Definition: OFHTTPRequest.m:33
of_string_encoding_t
The encoding of a string.
Definition: OFString.h:50
of_http_request_method_t
The type of an HTTP request.
Definition: OFHTTPRequest.h:36
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
Definition: OFHTTPRequest.h:44
Definition: OFHTTPRequest.h:52
A class for handling strings.
Definition: OFString.h:91
A class for storing arbitrary data in an array.
Definition: OFDataArray.h:37
Definition: OFHTTPRequest.h:48
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:61
uint8_t major
Definition: OFHTTPRequest.h:63
of_http_request_method_t of_http_request_method_from_string(const char *string)
Returns the request method for the specified string.
Definition: OFHTTPRequest.m:58
The HTTP version of the HTTP request.
Definition: OFHTTPRequest.h:61
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:73
Definition: OFHTTPRequest.h:50
A protocol for the creation of copies.
Definition: OFObject.h:896
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:29
Definition: OFHTTPRequest.h:40
Definition: OFHTTPRequest.h:42
uint8_t minor
Definition: OFHTTPRequest.h:65