Differences From Artifact [b02049e5b7]:
- File
src/OFHTTPClient.h
— part of check-in
[d3d4d34dad]
at
2017-09-23 19:02:10
on branch trunk
— OFHTTPClient: Add request performed callback
This is in preparation for making OFHTTPClient asynchronous. (user: js, size: 5523) [annotate] [blame] [check-ins using]
To Artifact [daaaeddb63]:
- File
src/OFHTTPClient.h
— part of check-in
[56a18442e2]
at
2017-09-24 00:59:12
on branch trunk
— Make OFHTTPClient asynchronous
This does not make OFHTTPClientResponse completely asynchronous yet.
Since -[initWithURL:] does not work well with an asynchronous API, it no
longer supports HTTP URLs. However, a new, asynchronous API will be
added as a replacement later on. (user: js, size: 5874) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPResponse; | > > | | < > > > > > > > > > > > > > > > > > > > > > > > | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFException; @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPResponse; @class OFTCPSocket; @class OFURL; /*! * @protocol OFHTTPClientDelegate OFHTTPClient.h ObjFW/OFHTTPClient.h * * @brief A delegate for OFHTTPClient. */ @protocol OFHTTPClientDelegate <OFObject> /*! * @brief A callback which is called when an OFHTTPClient performed a request. * * @param client The OFHTTPClient which performed the request * @param request The request the OFHTTPClient performed * @param response The response to the request performed */ - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response; /*! * @brief A callback which is called when an OFHTTPClient encountered an * exception while performing a request. * * @param client The client which encountered an exception * @param exception The exception the client encountered * @param request The request during which the client encountered the exception */ - (void)client: (OFHTTPClient *)client didEncounterException: (id)exception forRequest: (OFHTTPRequest *)request; @optional /*! * @brief A callback which is called when an OFHTTPClient creates a socket. * * This is useful if the connection is using HTTPS and the server requires a * client certificate. This callback can then be used to tell the TLS socket * about the certificate. Another use case is to tell the socket about a SOCKS5 * proxy it should use for this connection. * * @param client The OFHTTPClient that created a socket * @param socket The socket created by the OFHTTPClient * @param request The request for which the socket was created */ - (void)client: (OFHTTPClient *)client didCreateSocket: (OF_KINDOF(OFTCPSocket *))socket forRequest: (OFHTTPRequest *)request; /*! * @brief A callback which is called when an OFHTTPClient received headers. * * @param client The OFHTTPClient which received the headers * @param headers The headers received * @param statusCode The status code received |
︙ | ︙ | |||
91 92 93 94 95 96 97 | * @return A boolean whether the OFHTTPClient should follow the redirect */ - (bool)client: (OFHTTPClient *)client shouldFollowRedirect: (OFURL *)URL statusCode: (int)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response; | < < < < < < < < < < < > > > | | 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 | * @return A boolean whether the OFHTTPClient should follow the redirect */ - (bool)client: (OFHTTPClient *)client shouldFollowRedirect: (OFURL *)URL statusCode: (int)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response; @end /*! * @class OFHTTPClient OFHTTPClient.h ObjFW/OFHTTPClient.h * * @brief A class for performing HTTP requests. */ @interface OFHTTPClient: OFObject { #ifdef OF_HTTPCLIENT_M @public #endif id <OFHTTPClientDelegate> _delegate; bool _insecureRedirectsAllowed, _inProgress; OFTCPSocket *_socket; OFURL *_lastURL; bool _lastWasHEAD; OFHTTPResponse *_lastResponse; } /*! |
︙ | ︙ | |||
138 139 140 141 142 143 144 | * @brief Creates a new OFHTTPClient. * * @return A new, autoreleased OFHTTPClient */ + (instancetype)client; /*! | | < < | | | < | | | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | * @brief Creates a new OFHTTPClient. * * @return A new, autoreleased OFHTTPClient */ + (instancetype)client; /*! * @brief Asynchronously performs the specified HTTP request. */ - (void)performRequest: (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 */ - (void)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; /*! * @brief Closes connections that are still open due to keep-alive. */ - (void)close; @end OF_ASSUME_NONNULL_END |