ObjFW
Loading...
Searching...
No Matches
OFHTTPClient.h
1/*
2 * Copyright (c) 2008-2024 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
22#ifndef OF_HAVE_SOCKETS
23# error No sockets available!
24#endif
25
26OF_ASSUME_NONNULL_BEGIN
27
28@class OFDictionary OF_GENERIC(KeyType, ObjectType);
29@class OFHTTPClient;
30@class OFHTTPRequest;
31@class OFHTTPResponse;
32@class OFIRI;
33@class OFStream;
34@class OFTCPSocket;
35@class OFTLSStream;
36
42@protocol OFHTTPClientDelegate <OFObject>
52- (void)client: (OFHTTPClient *)client
53 didPerformRequest: (OFHTTPRequest *)request
54 response: (nullable OFHTTPResponse *)response
55 exception: (nullable id)exception;
56
57@optional
69- (void)client: (OFHTTPClient *)client
70 didCreateTCPSocket: (OFTCPSocket *)TCPSocket
71 request: (OFHTTPRequest *)request;
72
84- (void)client: (OFHTTPClient *)client
85 didCreateTLSStream: (OFTLSStream *)TLSStream
86 request: (OFHTTPRequest *)request;
87
97- (void)client: (OFHTTPClient *)client
98 wantsRequestBody: (OFStream *)requestBody
99 request: (OFHTTPRequest *)request;
100
110- (void)client: (OFHTTPClient *)client
111 didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers
112 statusCode: (short)statusCode
113 request: (OFHTTPRequest *)request;
114
139- (bool)client: (OFHTTPClient *)client
140 shouldFollowRedirectToIRI: (OFIRI *)IRI
141 statusCode: (short)statusCode
142 request: (OFHTTPRequest *)request
143 response: (OFHTTPResponse *)response;
144@end
145
151OF_SUBCLASSING_RESTRICTED
153{
154#ifdef OF_HTTP_CLIENT_M
155@public
156#endif
157 OFObject <OFHTTPClientDelegate> *_Nullable _delegate;
158 bool _allowsInsecureRedirects, _inProgress;
159 OFStream *_Nullable _stream;
160 OFIRI *_Nullable _lastIRI;
161 bool _lastWasHEAD;
162 OFHTTPResponse *_Nullable _lastResponse;
163}
164
168@property OF_NULLABLE_PROPERTY (assign, nonatomic)
169 OFObject <OFHTTPClientDelegate> *delegate;
170
174@property (nonatomic) bool allowsInsecureRedirects;
175
181+ (instancetype)client;
182
198- (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request;
199
218- (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request
219 redirects: (unsigned int)redirects;
220
227- (void)asyncPerformRequest: (OFHTTPRequest *)request;
228
238- (void)asyncPerformRequest: (OFHTTPRequest *)request
239 redirects: (unsigned int)redirects;
240
244- (void)close;
245@end
246
247OF_ASSUME_NONNULL_END
An abstract class for storing objects in a dictionary.
Definition OFDictionary.h:84
A class for performing HTTP requests.
Definition OFHTTPClient.h:153
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:692
A base class for different types of streams.
Definition OFStream.h:192
A class for handling strings.
Definition OFString.h:139
A class which provides methods to create and use TCP sockets.
Definition OFTCPSocket.h:71
A class that provides Transport Layer Security on top of a stream.
Definition OFTLSStream.h:78