21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
+
-
|
OF_ASSUME_NONNULL_BEGIN
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFHTTPClient;
@class OFHTTPRequest;
@class OFHTTPResponse;
@class OFIRI;
@class OFStream;
@class OFTCPSocket;
@class OFTLSStream;
@class OFURI;
/**
* @protocol OFHTTPClientDelegate OFHTTPClient.h ObjFW/OFHTTPClient.h
*
* @brief A delegate for OFHTTPClient.
*/
@protocol OFHTTPClientDelegate <OFObject>
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
-
+
-
+
-
+
-
+
|
* to detect a redirect.
*
* This callback will only be called if the OFHTTPClient will follow a
* redirect. If the maximum number of redirects has been reached already, this
* callback will not be called.
*
* @param client The OFHTTPClient which wants to follow a redirect
* @param URI The URI to which it will follow a redirect
* @param IRI The IRI to which it will follow a redirect
* @param statusCode The status code for the redirection
* @param request The request for which the OFHTTPClient wants to redirect.
* You are allowed to change the request's headers from this
* callback and they will be used when following the redirect
* (e.g. to set the cookies for the new URI), however, keep in
* (e.g. to set the cookies for the new IRI), however, keep in
* mind that this will change the request you originally passed.
* @param response The response indicating the redirect
* @return A boolean whether the OFHTTPClient should follow the redirect
*/
- (bool)client: (OFHTTPClient *)client
shouldFollowRedirectToURI: (OFURI *)URI
shouldFollowRedirectToIRI: (OFIRI *)IRI
statusCode: (short)statusCode
request: (OFHTTPRequest *)request
response: (OFHTTPResponse *)response;
@end
/**
* @class OFHTTPClient OFHTTPClient.h ObjFW/OFHTTPClient.h
*
* @brief A class for performing HTTP requests.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFHTTPClient: OFObject
{
#ifdef OF_HTTP_CLIENT_M
@public
#endif
OFObject <OFHTTPClientDelegate> *_Nullable _delegate;
bool _allowsInsecureRedirects, _inProgress;
OFStream *_Nullable _stream;
OFURI *_Nullable _lastURI;
OFIRI *_Nullable _lastIRI;
bool _lastWasHEAD;
OFHTTPResponse *_Nullable _lastResponse;
}
/**
* @brief The delegate of the HTTP request.
*/
|
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
-
+
-
+
-
+
-
+
|
*
* @param request The request to perform
* @return The OFHTTPResponse for the request
* @throw OFHTTPRequestFailedException The HTTP request failed
* @throw OFInvalidServerResponseException The server sent an invalid response
* @throw OFUnsupportedVersionException The server responded in an unsupported
* version
* @throw OFAlreadyConnectedException The client is already performing a request
* @throw OFAlreadyOpenException The client is already performing a request
*/
- (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request;
/**
* @brief Synchronously performs the specified HTTP request.
*
* @note You must not change the delegate while a synchronous request is
* running! If you want to change the delegate during the request,
* perform an asynchronous request instead!
*
* @param request The request to perform
* @param redirects The maximum number of redirects after which no further
* attempt is done to follow the redirect, but instead the
* redirect is treated as an OFHTTPResponse
* @return The OFHTTPResponse for the request
* @throw OFHTTPRequestFailedException The HTTP request failed
* @throw OFInvalidServerResponseException The server sent an invalid response
* @throw OFUnsupportedVersionException The server responded in an unsupported
* version
* @throw OFAlreadyConnectedException The client is already performing a request
* @throw OFAlreadyOpenException The client is already performing a request
*/
- (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request
redirects: (unsigned int)redirects;
/**
* @brief Asynchronously performs the specified HTTP request.
*
* @param request The request to perform
* @throw OFAlreadyConnectedException The client is already performing a request
* @throw OFAlreadyOpenException The client is already performing a request
*/
- (void)asyncPerformRequest: (OFHTTPRequest *)request;
/**
* @brief Asynchronously performs the specified HTTP request.
*
* @param request The request to perform
* @param redirects The maximum number of redirects after which no further
* attempt is done to follow the redirect, but instead the
* redirect is treated as an OFHTTPResponse
* @throw OFAlreadyConnectedException The client is already performing a request
* @throw OFAlreadyOpenException The client is already performing a request
*/
- (void)asyncPerformRequest: (OFHTTPRequest *)request
redirects: (unsigned int)redirects;
/**
* @brief Closes connections that are still open due to keep-alive.
*/
- (void)close;
@end
OF_ASSUME_NONNULL_END
|