ObjFW
OFHTTPClient.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 
18 #ifndef OF_HAVE_SOCKETS
19 # error No sockets available!
20 #endif
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
24 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
25 @class OFHTTPClient;
26 @class OFHTTPRequest;
27 @class OFHTTPResponse;
28 @class OFStream;
29 @class OFTCPSocket;
30 @class OFURL;
31 
46 - (void)client: (OFHTTPClient *)client
47  didPerformRequest: (OFHTTPRequest *)request
48  response: (nullable OFHTTPResponse *)response
49  exception: (nullable id)exception;
50 
51 @optional
64 - (void)client: (OFHTTPClient *)client
65  didCreateSocket: (OFTCPSocket *)socket
66  request: (OFHTTPRequest *)request;
67 
77 - (void)client: (OFHTTPClient *)client
78  wantsRequestBody: (OFStream *)requestBody
79  request: (OFHTTPRequest *)request;
80 
90 - (void)client: (OFHTTPClient *)client
91  didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers
92  statusCode: (short)statusCode
93  request: (OFHTTPRequest *)request;
94 
119 - (bool)client: (OFHTTPClient *)client
120  shouldFollowRedirect: (OFURL *)URL
121  statusCode: (short)statusCode
122  request: (OFHTTPRequest *)request
123  response: (OFHTTPResponse *)response;
124 @end
125 
131 OF_SUBCLASSING_RESTRICTED
133 {
134 #ifdef OF_HTTPCLIENT_M
135 @public
136 #endif
137  OFObject <OFHTTPClientDelegate> *_Nullable _delegate;
138  bool _allowsInsecureRedirects, _inProgress;
139  OFTCPSocket *_Nullable _socket;
140  OFURL *_Nullable _lastURL;
141  bool _lastWasHEAD;
142  OFHTTPResponse *_Nullable _lastResponse;
143 }
144 
148 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
150 
154 @property (nonatomic) bool allowsInsecureRedirects;
155 
161 + (instancetype)client;
162 
173 - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request;
174 
188 - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request
189  redirects: (unsigned int)redirects;
190 
196 - (void)asyncPerformRequest: (OFHTTPRequest *)request;
197 
206 - (void)asyncPerformRequest: (OFHTTPRequest *)request
207  redirects: (unsigned int)redirects;
208 
212 - (void)close;
213 @end
214 
215 OF_ASSUME_NONNULL_END
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:58
A class for performing HTTP requests.
Definition: OFHTTPClient.h:133
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:74
A class for representing an HTTP request reply as a stream.
Definition: OFHTTPResponse.h:30
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A base class for different types of streams.
Definition: OFStream.h:191
A class for handling strings.
Definition: OFString.h:132
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:67
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:34
A delegate for OFHTTPClient.
Definition: OFHTTPClient.h:37