ObjFW
OFHTTPClient.h
1 /*
2  * Copyright (c) 2008-2023 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 OFIRI;
29 @class OFStream;
30 @class OFTCPSocket;
31 @class OFTLSStream;
32 
48 - (void)client: (OFHTTPClient *)client
49  didPerformRequest: (OFHTTPRequest *)request
50  response: (nullable OFHTTPResponse *)response
51  exception: (nullable id)exception;
52 
53 @optional
65 - (void)client: (OFHTTPClient *)client
66  didCreateTCPSocket: (OFTCPSocket *)TCPSocket
67  request: (OFHTTPRequest *)request;
68 
80 - (void)client: (OFHTTPClient *)client
81  didCreateTLSStream: (OFTLSStream *)TLSStream
82  request: (OFHTTPRequest *)request;
83 
93 - (void)client: (OFHTTPClient *)client
94  wantsRequestBody: (OFStream *)requestBody
95  request: (OFHTTPRequest *)request;
96 
106 - (void)client: (OFHTTPClient *)client
107  didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers
108  statusCode: (short)statusCode
109  request: (OFHTTPRequest *)request;
110 
135 - (bool)client: (OFHTTPClient *)client
136  shouldFollowRedirectToIRI: (OFIRI *)IRI
137  statusCode: (short)statusCode
138  request: (OFHTTPRequest *)request
139  response: (OFHTTPResponse *)response;
140 @end
141 
147 OF_SUBCLASSING_RESTRICTED
149 {
150 #ifdef OF_HTTP_CLIENT_M
151 @public
152 #endif
153  OFObject <OFHTTPClientDelegate> *_Nullable _delegate;
154  bool _allowsInsecureRedirects, _inProgress;
155  OFStream *_Nullable _stream;
156  OFIRI *_Nullable _lastIRI;
157  bool _lastWasHEAD;
158  OFHTTPResponse *_Nullable _lastResponse;
159 }
160 
164 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
166 
170 @property (nonatomic) bool allowsInsecureRedirects;
171 
177 + (instancetype)client;
178 
194 - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request;
195 
214 - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request
215  redirects: (unsigned int)redirects;
216 
223 - (void)asyncPerformRequest: (OFHTTPRequest *)request;
224 
234 - (void)asyncPerformRequest: (OFHTTPRequest *)request
235  redirects: (unsigned int)redirects;
236 
240 - (void)close;
241 @end
242 
243 OF_ASSUME_NONNULL_END
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:80
A class for performing HTTP requests.
Definition: OFHTTPClient.h:149
A class for storing HTTP requests.
Definition: OFHTTPRequest.h:71
A class for representing an HTTP request response as a stream.
Definition: OFHTTPResponse.h:33
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:37
The root class for all other classes inside ObjFW.
Definition: OFObject.h:688
A base class for different types of streams.
Definition: OFStream.h:188
A class for handling strings.
Definition: OFString.h:135
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:67
A class that provides Transport Layer Security on top of a stream.
Definition: OFTLSStream.h:75
A delegate for OFHTTPClient.
Definition: OFHTTPClient.h:38