ObjFW
OFHTTPClient.h
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 
19 #ifndef OF_HAVE_SOCKETS
20 # error No sockets available!
21 #endif
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
25 @class OFHTTPClient;
26 @class OFHTTPRequest;
27 @class OFHTTPResponse;
28 @class OFURL;
29 @class OFTCPSocket;
30 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
31 @class OFDataArray;
32 
39 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
40 @optional
41 #endif
42 
54 - (void)client: (OFHTTPClient*)client
55  didCreateSocket: (OFTCPSocket*)socket
56  request: (OFHTTPRequest*)request;
57 
67 - (void)client: (OFHTTPClient*)client
68  didReceiveHeaders: (OFDictionary OF_GENERIC(OFString*, OFString*)*)headers
69  statusCode: (int)statusCode
70  request: (OFHTTPRequest*)request;
71 
91 - (bool)client: (OFHTTPClient*)client
92  shouldFollowRedirect: (OFURL*)URL
93  statusCode: (int)statusCode
94  request: (OFHTTPRequest*)request;
95 @end
96 
103 {
104  id <OFHTTPClientDelegate> _delegate;
105  bool _insecureRedirectsAllowed;
106  OFTCPSocket *_socket;
107  OFURL *_lastURL;
108  bool _lastWasHEAD;
109  OFHTTPResponse *_lastResponse;
110 }
111 
112 #ifdef OF_HAVE_PROPERTIES
113 @property OF_NULLABLE_PROPERTY (assign) id <OFHTTPClientDelegate> delegate;
114 @property bool insecureRedirectsAllowed;
115 #endif
116 
122 + (instancetype)client;
123 
129 - (void)setDelegate: (nullable id <OFHTTPClientDelegate>)delegate;
130 
136 - (nullable id <OFHTTPClientDelegate>)delegate;
137 
143 - (void)setInsecureRedirectsAllowed: (bool)allowed;
144 
150 - (bool)insecureRedirectsAllowed;
151 
157 - (OFHTTPResponse*)performRequest: (OFHTTPRequest*)request;
158 
168 - (OFHTTPResponse*)performRequest: (OFHTTPRequest*)request
169  redirects: (size_t)redirects;
170 
174 - (void)close;
175 @end
176 
177 @interface OFObject (OFHTTPClientDelegate) <OFHTTPClientDelegate>
178 @end
179 
180 OF_ASSUME_NONNULL_END
A class for performing HTTP requests.
Definition: OFHTTPClient.h:102
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
A class for representing an HTTP request reply as a stream.
Definition: OFHTTPResponse.h:29
A class for handling strings.
Definition: OFString.h:91
A class for storing arbitrary data in an array.
Definition: OFDataArray.h:37
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:61
A class which provides functions to create and use TCP sockets.
Definition: OFTCPSocket.h:61
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:73
A delegate for OFHTTPClient.
Definition: OFHTTPClient.h:38
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:29