ObjFW
OFHTTPClient.h
1 /*
2  * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #import "OFRunLoop.h"
22 
23 #ifndef OF_HAVE_SOCKETS
24 # error No sockets available!
25 #endif
26 
27 OF_ASSUME_NONNULL_BEGIN
28 
29 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
30 @class OFHTTPClient;
31 @class OFHTTPClientResponse;
32 @class OFHTTPRequest;
33 @class OFHTTPResponse;
34 @class OFIRI;
35 @class OFStream;
36 @class OFTCPSocket;
37 @class OFTLSStream;
38 
54 - (void)client: (OFHTTPClient *)client
55  didPerformRequest: (OFHTTPRequest *)request
56  response: (nullable OFHTTPResponse *)response
57  exception: (nullable id)exception;
58 
59 @optional
71 - (void)client: (OFHTTPClient *)client
72  didCreateTCPSocket: (OFTCPSocket *)TCPSocket
73  request: (OFHTTPRequest *)request;
74 
86 - (void)client: (OFHTTPClient *)client
87  didCreateTLSStream: (OFTLSStream *)TLSStream
88  request: (OFHTTPRequest *)request;
89 
110 - (void)client: (OFHTTPClient *)client
111  wantsRequestBody: (OFStream *)requestBody
112  request: (OFHTTPRequest *)request;
113 
123 - (void)client: (OFHTTPClient *)client
124  didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers
125  statusCode: (short)statusCode
126  request: (OFHTTPRequest *)request;
127 
152 - (bool)client: (OFHTTPClient *)client
153  shouldFollowRedirectToIRI: (OFIRI *)IRI
154  statusCode: (short)statusCode
155  request: (OFHTTPRequest *)request
156  response: (OFHTTPResponse *)response;
157 @end
158 
164 OF_SUBCLASSING_RESTRICTED
166 {
167 #ifdef OF_HTTP_CLIENT_M
168 @public
169 #endif
170  OFObject <OFHTTPClientDelegate> *_Nullable _delegate;
171  bool _allowsInsecureRedirects, _inProgress;
172  OFStream *_Nullable _stream;
173  OFIRI *_Nullable _lastIRI;
174  bool _lastWasHEAD;
175  OFHTTPClientResponse *_Nullable _lastResponse;
176 }
177 
181 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
183 
187 @property (nonatomic) bool allowsInsecureRedirects;
188 
194 + (instancetype)client;
195 
211 - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request;
212 
231 - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request
232  redirects: (unsigned int)redirects;
233 
240 - (void)asyncPerformRequest: (OFHTTPRequest *)request;
241 
251 - (void)asyncPerformRequest: (OFHTTPRequest *)request
252  redirects: (unsigned int)redirects;
253 
264 - (void)asyncPerformRequest: (OFHTTPRequest *)request
265  redirects: (unsigned int)redirects
266  runLoopMode: (OFRunLoopMode)runLoopMode;
267 
271 - (void)close;
272 @end
273 
274 OF_ASSUME_NONNULL_END
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:84
A class for performing HTTP requests.
Definition: OFHTTPClient.h:166
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:75
A class for representing an HTTP request response as a stream.
Definition: OFHTTPResponse.h:37
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:41
The root class for all other classes inside ObjFW.
Definition: OFObject.h:956
A base class for different types of streams.
Definition: OFStream.h:280
A class for handling strings.
Definition: OFString.h:143
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:86
A class that provides Transport Layer Security on top of a stream.
Definition: OFTLSStream.h:102
A delegate for OFHTTPClient.
Definition: OFHTTPClient.h:44