7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#ifndef HTTP_CLIENT_H
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#define HTTP_CLIENT_H
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch#include "net.h"
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch
fab1c263d60ee6a08f162af2146ff0ccf6b36061Stephan Bosch#include "http-common.h"
1920ef85b63738a06914e56508049dd0afe38732Timo Sirainen#include "http-response.h"
eb325a5a90c1d2655e74972bde0de6a699d2c864Stephan Bosch
74c09aceb0118b564f8443e1276c465738d19c17Timo Sirainenstruct timeval;
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct http_response;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct http_client_request;
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschstruct http_client;
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschstruct http_client_context;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
c275cef636c79e1d08b3a82462c4abdca6f8cef3Martti Rannanjärvistruct ssl_iostream_settings;
c275cef636c79e1d08b3a82462c4abdca6f8cef3Martti Rannanjärvi
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/*
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch * Client settings
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch */
1d048c5050f03c24251e5af8087e640de21b2d62Timo Sirainen
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct http_client_settings {
7944646fad6aa1e7c649c3d33e454c516b0220b6Timo Sirainen /* a) If dns_client is set, all lookups are done via it.
7944646fad6aa1e7c649c3d33e454c516b0220b6Timo Sirainen b) If dns_client_socket_path is set, each DNS lookup does its own
7944646fad6aa1e7c649c3d33e454c516b0220b6Timo Sirainen dns-lookup UNIX socket connection.
7944646fad6aa1e7c649c3d33e454c516b0220b6Timo Sirainen c) Otherwise, blocking gethostbyname() lookups are used. */
7944646fad6aa1e7c649c3d33e454c516b0220b6Timo Sirainen struct dns_client *dns_client;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *dns_client_socket_path;
1e63e30812158e6446d81cdbb2f45954794d4f8aStephan Bosch unsigned int dns_ttl_msecs;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
c275cef636c79e1d08b3a82462c4abdca6f8cef3Martti Rannanjärvi const struct ssl_iostream_settings *ssl;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen /* User-Agent: header (default: none) */
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen const char *user_agent;
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen
ede750711f27ca9d9037a7ab9f016411b57f1ad9Stephan Bosch /* proxy on unix socket */
ede750711f27ca9d9037a7ab9f016411b57f1ad9Stephan Bosch const char *proxy_socket_path;
ede750711f27ca9d9037a7ab9f016411b57f1ad9Stephan Bosch /* URL for normal proxy (ignored if proxy_socket_path is set) */
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch const struct http_url *proxy_url;
ede750711f27ca9d9037a7ab9f016411b57f1ad9Stephan Bosch /* credentials for proxy */
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch const char *proxy_username;
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch const char *proxy_password;
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* directory for writing raw log data for debugging purposes */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *rawlog_dir;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* maximum time a connection will idle. if parallel connections are idle,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch the duplicates will end earlier based on how many idle connections exist
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch to that same service */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int max_idle_time_msecs;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* maximum number of parallel connections per peer (default = 1) */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int max_parallel_connections;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* maximum number of pipelined requests per connection (default = 1) */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int max_pipelined_requests;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
ad03049781fc14807248007d524be4daf06c3ee2Stephan Bosch /* don't automatically act upon redirect responses */
ad03049781fc14807248007d524be4daf06c3ee2Stephan Bosch bool no_auto_redirect;
ad03049781fc14807248007d524be4daf06c3ee2Stephan Bosch
486c7c8d9e725e0227c7723aa43b7fce724eb9eeStephan Bosch /* never automatically retry requests */
486c7c8d9e725e0227c7723aa43b7fce724eb9eeStephan Bosch bool no_auto_retry;
486c7c8d9e725e0227c7723aa43b7fce724eb9eeStephan Bosch
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch /* if we use a proxy, delegate SSL negotiation to proxy, rather than
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch creating a CONNECT tunnel through the proxy for the SSL link */
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch bool no_ssl_tunnel;
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* maximum number of redirects for a request
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch (default = 0; redirects refused)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int max_redirects;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* maximum number of attempts for a request */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int max_attempts;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch /* maximum number of connection attempts to a host before all associated
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch requests fail.
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch if > 1, the maximum will be enforced across all IPs for that host,
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch meaning that IPs may be tried more than once eventually if the number
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch of IPs is smaller than the specified maximum attempts. If the number of IPs
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch is higher than the maximum attempts, not all IPs are tried. If <= 1, all
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch IPs are tried at most once.
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch */
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch unsigned int max_connect_attempts;
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch
fe2b0e3de834dd40b698bb579adc5357d5789ec9Stephan Bosch /* Initial backoff time; doubled at each connection failure */
fe2b0e3de834dd40b698bb579adc5357d5789ec9Stephan Bosch unsigned int connect_backoff_time_msecs;
94d1b08c9e20d637db568a3eab3dfc2b9e96e62aStephan Bosch /* Maximum backoff time */
94d1b08c9e20d637db568a3eab3dfc2b9e96e62aStephan Bosch unsigned int connect_backoff_max_time_msecs;
fe2b0e3de834dd40b698bb579adc5357d5789ec9Stephan Bosch
feba5e502b2131c9a1c766b7ef9ff041dbf71d1dStephan Bosch /* response header limits */
feba5e502b2131c9a1c766b7ef9ff041dbf71d1dStephan Bosch struct http_header_limits response_hdr_limits;
feba5e502b2131c9a1c766b7ef9ff041dbf71d1dStephan Bosch
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch /* max total time to wait for HTTP request to finish
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch this can be overridden/reset for individual requests using
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch http_client_request_set_timeout() and friends.
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch (default is no timeout)
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch */
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch unsigned int request_absolute_timeout_msecs;
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen /* max time to wait for HTTP request to finish before retrying
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen (default = unlimited) */
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen unsigned int request_timeout_msecs;
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen /* max time to wait for connect() (and SSL handshake) to finish before
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen retrying (default = request_timeout_msecs) */
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen unsigned int connect_timeout_msecs;
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen /* time to wait for connect() (and SSL handshake) to finish for the first
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen connection before trying the next IP in parallel
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen (default = 0; wait until current connection attempt finishes) */
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen unsigned int soft_connect_timeout_msecs;
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch /* maximum acceptable delay in seconds for automatically
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch retrying/redirecting requests. if a server sends a response with a
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch Retry-After header that causes a delay longer than this, the request
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch is not automatically retried and the response is returned */
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch unsigned int max_auto_retry_delay;
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch /* the kernel send/receive buffer sizes used for the connection sockets.
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch Configuring this is mainly useful for the test suite. The kernel
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch defaults are used when these settings are 0. */
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch size_t socket_send_buffer_size;
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch size_t socket_recv_buffer_size;
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch
2d1ad5742dd723b39c51bcf64c62a600237de8aeTimo Sirainen /* Event to use for the http client. For specific requests this can be
2d1ad5742dd723b39c51bcf64c62a600237de8aeTimo Sirainen overridden with http_client_request_set_event(). */
2d1ad5742dd723b39c51bcf64c62a600237de8aeTimo Sirainen struct event *event;
2d1ad5742dd723b39c51bcf64c62a600237de8aeTimo Sirainen
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* enable logging debug messages */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch bool debug;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch};
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/*
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch * Request
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschenum http_client_request_error {
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* The request was aborted */
a8741f46cb3cf40e58e3d47b263f238918243380Stephan Bosch HTTP_CLIENT_REQUEST_ERROR_ABORTED = HTTP_RESPONSE_STATUS_INTERNAL,
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch /* Failed to parse HTTP target url */
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch HTTP_CLIENT_REQUEST_ERROR_INVALID_URL,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Failed to perform DNS lookup for the host */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Failed to setup any connection for the host and client settings allowed
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch no more attempts */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_CLIENT_REQUEST_ERROR_CONNECT_FAILED,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Service returned an invalid redirect response for this request */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_CLIENT_REQUEST_ERROR_INVALID_REDIRECT,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* The connection was lost unexpectedly while handling the request and
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch client settings allowed no more attempts */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_CLIENT_REQUEST_ERROR_CONNECTION_LOST,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* The input stream passed to the request using
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch http_client_request_set_payload() returned an error while sending the
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch request. */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_CLIENT_REQUEST_ERROR_BROKEN_PAYLOAD,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* The service returned a bad response */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_CLIENT_REQUEST_ERROR_BAD_RESPONSE,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* The request timed out (either this was the last attempt or the
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch absolute timeout was hit) */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_CLIENT_REQUEST_ERROR_TIMED_OUT,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch};
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschenum http_request_state {
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* New request; not yet submitted */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_NEW = 0,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Request is queued; waiting for a connection */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_QUEUED,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Request header is sent; still sending request payload to server */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_PAYLOAD_OUT,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Request is fully sent; waiting for response */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_WAITING,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Response header is received for the request */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_GOT_RESPONSE,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Reading response payload; response handler still needs to read more
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch payload. */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_PAYLOAD_IN,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Request is finished; still lingering due to references */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_FINISHED,
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch /* Request is aborted; still lingering due to references */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch HTTP_REQUEST_STATE_ABORTED
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch};
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschextern const char *http_request_state_names[];
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Boschstruct http_client_tunnel {
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch int fd_in, fd_out;
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch struct istream *input;
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch struct ostream *output;
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch};
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Boschstruct http_client_request_stats {
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch /* Total elapsed time since message was submitted */
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch unsigned int total_msecs;
bf7740f6bcea93a45e68113f1334c2be7f3cea4dTimo Sirainen /* Elapsed time since message was first sent */
bf7740f6bcea93a45e68113f1334c2be7f3cea4dTimo Sirainen unsigned int first_sent_msecs;
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch /* Elapsed time since message was last sent */
bf7740f6bcea93a45e68113f1334c2be7f3cea4dTimo Sirainen unsigned int last_sent_msecs;
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch /* Time spent in other ioloops */
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch unsigned int other_ioloop_msecs;
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch /* Time spent in the http-client's own ioloop */
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch unsigned int http_ioloop_msecs;
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch /* Total time spent on waiting for file locks */
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch unsigned int lock_msecs;
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch
eaf49d968f5cbda1de3ccd45ce4d764d4bed2352Stephan Bosch /* Number of times this request was retried */
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch unsigned int attempts;
eaf49d968f5cbda1de3ccd45ce4d764d4bed2352Stephan Bosch /* Number of times the client attempted to actually send the request
eaf49d968f5cbda1de3ccd45ce4d764d4bed2352Stephan Bosch to a server */
eaf49d968f5cbda1de3ccd45ce4d764d4bed2352Stephan Bosch unsigned int send_attempts;
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch};
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschtypedef void
7384b4e78eaab44693c985192276e31322155e32Stephan Boschhttp_client_request_callback_t(const struct http_response *response,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch void *context);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch/* create new HTTP request */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct http_client_request *
7384b4e78eaab44693c985192276e31322155e32Stephan Boschhttp_client_request(struct http_client *client,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *method, const char *host, const char *target,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch http_client_request_callback_t *callback, void *context);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#define http_client_request(client, method, host, target, callback, context) \
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch http_client_request(client, method, host, target + \
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch CALLBACK_TYPECHECK(callback, void (*)( \
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const struct http_response *response, typeof(context))), \
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch (http_client_request_callback_t *)callback, context)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* create net HTTP request using provided URL. This implicitly sets
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch port, ssl, and username:password if provided. */
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Boschstruct http_client_request *
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Boschhttp_client_request_url(struct http_client *client,
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch const char *method, const struct http_url *target_url,
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch http_client_request_callback_t *callback, void *context);
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch#define http_client_request_url(client, method, target_url, callback, context) \
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch http_client_request_url(client, method, target_url + \
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch CALLBACK_TYPECHECK(callback, void (*)( \
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch const struct http_response *response, typeof(context))), \
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch (http_client_request_callback_t *)callback, context)
e46130f48a6962734bfde7e71906d3894bedf45bStephan Boschstruct http_client_request *
e46130f48a6962734bfde7e71906d3894bedf45bStephan Boschhttp_client_request_url_str(struct http_client *client,
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch const char *method, const char *url_str,
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch http_client_request_callback_t *callback, void *context);
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch#define http_client_request_url_str(client, method, url_str, callback, context) \
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch http_client_request_url_str(client, method, url_str + \
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch CALLBACK_TYPECHECK(callback, void (*)( \
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch const struct http_response *response, typeof(context))), \
e46130f48a6962734bfde7e71906d3894bedf45bStephan Bosch (http_client_request_callback_t *)callback, context)
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch/* create new HTTP CONNECT request. If this HTTP is configured to use a proxy,
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch a CONNECT request will be submitted at that proxy, otherwise the connection
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch is created directly. Call http_client_request_start_tunnel() to
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch to take over the connection.
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch */
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Boschstruct http_client_request *
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Boschhttp_client_request_connect(struct http_client *client,
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch const char *host, in_port_t port,
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch http_client_request_callback_t *callback,
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch void *context);
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch#define http_client_request_connect(client, host, port, callback, context) \
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch http_client_request_connect(client, host, port + \
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch CALLBACK_TYPECHECK(callback, void (*)( \
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch const struct http_response *response, typeof(context))), \
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch (http_client_request_callback_t *)callback, context)
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* same as http_client_request_connect, but uses an IP rather than a host
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch name. */
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Boschstruct http_client_request *
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Boschhttp_client_request_connect_ip(struct http_client *client,
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch const struct ip_addr *ip, in_port_t port,
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch http_client_request_callback_t *callback,
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch void *context);
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch#define http_client_request_connect_ip(client, ip, port, callback, context) \
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch http_client_request_connect_ip(client, ip, port + \
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch CALLBACK_TYPECHECK(callback, void (*)( \
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch const struct http_response *response, typeof(context))), \
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch (http_client_request_callback_t *)callback, context)
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch
2d1ad5742dd723b39c51bcf64c62a600237de8aeTimo Sirainenvoid http_client_request_set_event(struct http_client_request *req,
2d1ad5742dd723b39c51bcf64c62a600237de8aeTimo Sirainen struct event *event);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* set the port for the service the request is directed at */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_request_set_port(struct http_client_request *req,
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch in_port_t port);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* indicate whether service the request is directed at uses ssl */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_request_set_ssl(struct http_client_request *req,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch bool ssl);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* set the urgent flag: this means that this request will get priority over
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch non-urgent request. Also, if no idle connection is available, a new
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch connection is created. Urgent requests are never pipelined. */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_request_set_urgent(struct http_client_request *req);
93c9909f68f7d057e38cca3b4612ec8d0bf42999Timo Sirainenvoid http_client_request_set_preserve_exact_reason(struct http_client_request *req);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* add a custom header to the request. This can override headers that are
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch otherwise created implicitly. */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_request_add_header(struct http_client_request *req,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *key, const char *value);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* remove a header added earlier. This has no influence on implicitly created
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch headers. */
84740b03d3ee9e96a2e446a54729188764c99292Timo Sirainenvoid http_client_request_remove_header(struct http_client_request *req,
84740b03d3ee9e96a2e446a54729188764c99292Timo Sirainen const char *key);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* set the value of the "Date" header for the request using a time_t value.
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch Use this instead of setting it directly using
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch http_client_request_add_header() */
6d573191bea1a64d6046be070487a5705a2d0204Stephan Boschvoid http_client_request_set_date(struct http_client_request *req,
6d573191bea1a64d6046be070487a5705a2d0204Stephan Bosch time_t date);
6d573191bea1a64d6046be070487a5705a2d0204Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* assign an input stream for the outgoing payload of this request. The input
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch stream is read asynchronously while the request is sent to the server.
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch when sync=TRUE a "100 Continue" response is requested from the service. The
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch client will then postpone sending the payload until a provisional response
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch with code 100 is received. This way, an error response can be sent by the
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch service before any potentially big payload is transmitted. Use this only for
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch payload that can be large. */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_request_set_payload(struct http_client_request *req,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct istream *input, bool sync);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* assign payload data to the request. The data is copied to the request pool.
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch If your data is already durably allocated during the existence of the
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch request, you should consider using http_client_request_set_payload() with
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch a data input stream instead. This will avoid copying the data unnecessarily.
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch */
7a13cd2268a5a99d2975a1648d6d14ffe1b6ccb0Stephan Boschvoid http_client_request_set_payload_data(struct http_client_request *req,
7a13cd2268a5a99d2975a1648d6d14ffe1b6ccb0Stephan Bosch const unsigned char *data, size_t size);
4d1cc687f40dc2697005a4977e7ac40dda3d7dcfStephan Bosch/* send an empty payload for this request. This means that a Content-Length
4d1cc687f40dc2697005a4977e7ac40dda3d7dcfStephan Bosch header is generated with zero size. Calling this function is not necessary
4d1cc687f40dc2697005a4977e7ac40dda3d7dcfStephan Bosch for the standard POST and PUT methods, for which this is done implicitly if
4d1cc687f40dc2697005a4977e7ac40dda3d7dcfStephan Bosch there is no payload set. */
4d1cc687f40dc2697005a4977e7ac40dda3d7dcfStephan Boschvoid http_client_request_set_payload_empty(struct http_client_request *req);
eb325a5a90c1d2655e74972bde0de6a699d2c864Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* set an absolute timeout for this request specifically, overriding the
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch default client-wide absolute request timeout */
b66def5dadd3e7c250313a938d26ad113663f86bStephan Boschvoid http_client_request_set_timeout_msecs(struct http_client_request *req,
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch unsigned int msecs);
b66def5dadd3e7c250313a938d26ad113663f86bStephan Boschvoid http_client_request_set_timeout(struct http_client_request *req,
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch const struct timeval *time);
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch
5b6bfa39481f719c1fd6ed3febeaf7f0be9e8886Timo Sirainen/* Override http_client_settings.request_timeout_msecs */
5b6bfa39481f719c1fd6ed3febeaf7f0be9e8886Timo Sirainenvoid http_client_request_set_attempt_timeout_msecs(struct http_client_request *req,
5b6bfa39481f719c1fd6ed3febeaf7f0be9e8886Timo Sirainen unsigned int msecs);
5b6bfa39481f719c1fd6ed3febeaf7f0be9e8886Timo Sirainen/* Override http_client_settings.max_attempts */
5b6bfa39481f719c1fd6ed3febeaf7f0be9e8886Timo Sirainenvoid http_client_request_set_max_attempts(struct http_client_request *req,
5b6bfa39481f719c1fd6ed3febeaf7f0be9e8886Timo Sirainen unsigned int max_attempts);
5b6bfa39481f719c1fd6ed3febeaf7f0be9e8886Timo Sirainen
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* set the username:password credentials for this request for simple
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch authentication. This function is meant for simple schemes that use a
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch password. More complex schemes will need to be handled manually.
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch This currently only supports the "basic" authentication scheme. */
30f35cf5d1e1374d7fab4231e86144fc106a8e79Stephan Boschvoid http_client_request_set_auth_simple(struct http_client_request *req,
30f35cf5d1e1374d7fab4231e86144fc106a8e79Stephan Bosch const char *username, const char *password);
30f35cf5d1e1374d7fab4231e86144fc106a8e79Stephan Bosch
befccf297cba74009dfd0447a0dcea018af756feStephan Bosch/* Assign a proxy to use for this particular request. This overrides any
befccf297cba74009dfd0447a0dcea018af756feStephan Bosch proxy defined in the client settings. */
befccf297cba74009dfd0447a0dcea018af756feStephan Boschvoid http_client_request_set_proxy_url(struct http_client_request *req,
befccf297cba74009dfd0447a0dcea018af756feStephan Bosch const struct http_url *proxy_url);
befccf297cba74009dfd0447a0dcea018af756feStephan Bosch/* Like http_client_request_set_proxy_url(), but the proxy is behind a unix
befccf297cba74009dfd0447a0dcea018af756feStephan Bosch socket. */
befccf297cba74009dfd0447a0dcea018af756feStephan Boschvoid http_client_request_set_proxy_socket(struct http_client_request *req,
befccf297cba74009dfd0447a0dcea018af756feStephan Bosch const char *proxy_socket);
befccf297cba74009dfd0447a0dcea018af756feStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* delay handling of this request to a later time. This way, a request can be
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch submitted that is held for some time until a certain time period has passed.
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch */
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Boschvoid http_client_request_delay_until(struct http_client_request *req,
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch time_t time);
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Boschvoid http_client_request_delay(struct http_client_request *req,
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch time_t seconds);
de0181258ab66b527ad8dc7e51a8efa76b4658d0Stephan Boschvoid http_client_request_delay_msecs(struct http_client_request *req,
de0181258ab66b527ad8dc7e51a8efa76b4658d0Stephan Bosch unsigned int msecs);
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* return the HTTP method for the request */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschconst char *
2a9cadfccc8fb2c609eedbb929952b49181b6d25Stephan Boschhttp_client_request_get_method(const struct http_client_request *req)
2a9cadfccc8fb2c609eedbb929952b49181b6d25Stephan Bosch ATTR_PURE;
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* return the HTTP target for the request */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschconst char *
2a9cadfccc8fb2c609eedbb929952b49181b6d25Stephan Boschhttp_client_request_get_target(const struct http_client_request *req)
2a9cadfccc8fb2c609eedbb929952b49181b6d25Stephan Bosch ATTR_PURE;
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* return the request state */
1d048c5050f03c24251e5af8087e640de21b2d62Timo Sirainenenum http_request_state
2a9cadfccc8fb2c609eedbb929952b49181b6d25Stephan Boschhttp_client_request_get_state(const struct http_client_request *req)
2a9cadfccc8fb2c609eedbb929952b49181b6d25Stephan Bosch ATTR_PURE;
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch/* get statistics for the request */
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Boschvoid http_client_request_get_stats(struct http_client_request *req,
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch struct http_client_request_stats *stats);
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch/* append text with request statistics to provided string buffer */
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Boschvoid http_client_request_append_stats_text(struct http_client_request *req,
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch string_t *str);
28be42b4c27b0415da92ae7dd2c6e9cee2836c51Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* submit the request. It is queued for transmission to the service */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_request_submit(struct http_client_request *req);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* attempt to retry the request. This function is called within the request
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch callback. It returns false if the request cannot be retried */
6c768e0e1ca2da178e79f7435c32ced01f6bcb24Timo Sirainenbool http_client_request_try_retry(struct http_client_request *req);
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* abort the request immediately. It may still linger for a while when it is
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch already sent to the service, but the callback will not be called anymore. */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_request_abort(struct http_client_request **req);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* call the specified callback when HTTP request is destroyed. */
4124bebe6daab2cd05acb0416096fc47cb9abd92Timo Sirainenvoid http_client_request_set_destroy_callback(struct http_client_request *req,
4124bebe6daab2cd05acb0416096fc47cb9abd92Timo Sirainen void (*callback)(void *),
4124bebe6daab2cd05acb0416096fc47cb9abd92Timo Sirainen void *context);
e94584bf65f0985f1512a9f0c0651dfcc56ed0f2Aki Tuomi#define http_client_request_set_destroy_callback(req, callback, context) \
e94584bf65f0985f1512a9f0c0651dfcc56ed0f2Aki Tuomi http_client_request_set_destroy_callback(req, (void(*)(void*))callback, context + \
e94584bf65f0985f1512a9f0c0651dfcc56ed0f2Aki Tuomi CALLBACK_TYPECHECK(callback, void (*)(typeof(context))))
4124bebe6daab2cd05acb0416096fc47cb9abd92Timo Sirainen
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* submits request and blocks until the provided payload is sent. Multiple
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch calls are allowed; payload transmission is ended with
c3a4c931e95737a52e1cebeeb109a2e1cc4d47d6Timo Sirainen http_client_request_finish_payload(). If the sending fails, returns -1
c3a4c931e95737a52e1cebeeb109a2e1cc4d47d6Timo Sirainen and sets req=NULL to indicate that the request was freed, otherwise
c3a4c931e95737a52e1cebeeb109a2e1cc4d47d6Timo Sirainen returns 0 and req is unchanged. */
eb325a5a90c1d2655e74972bde0de6a699d2c864Stephan Boschint http_client_request_send_payload(struct http_client_request **req,
eb325a5a90c1d2655e74972bde0de6a699d2c864Stephan Bosch const unsigned char *data, size_t size);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* finish sending the payload. Always frees req and sets it to NULL.
c3a4c931e95737a52e1cebeeb109a2e1cc4d47d6Timo Sirainen Returns 0 on success, -1 on error. */
069b28a2ef54072a221fe4ac67aaeb4e83fee6c1Timo Sirainenint http_client_request_finish_payload(struct http_client_request **req);
eb325a5a90c1d2655e74972bde0de6a699d2c864Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* take over the connection this request was sent over for use as a HTTP
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch CONNECT tunnel. This only applies to requests that were created using
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch http_client_request_connect() or http_client_request_connect_ip(). */
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Boschvoid http_client_request_start_tunnel(struct http_client_request *req,
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch struct http_client_tunnel *tunnel);
a62fe4b300e2f591e939993aec4cac1e7ae30ad1Stephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/*
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch * Client
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
e7bc4ce82122c30696e60789432ffeb2e26b265bTimo Sirainen/* Create a client using the global shared client context. */
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschstruct http_client *
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschhttp_client_init(const struct http_client_settings *set);
ff8a751fb9227a4fd73b2cdaa16d7a2616b3e7e7Timo Sirainen/* Create a client without a shared context. */
ff8a751fb9227a4fd73b2cdaa16d7a2616b3e7e7Timo Sirainenstruct http_client *
ff8a751fb9227a4fd73b2cdaa16d7a2616b3e7e7Timo Sirainenhttp_client_init_private(const struct http_client_settings *set);
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschstruct http_client *
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschhttp_client_init_shared(struct http_client_context *cctx,
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Bosch const struct http_client_settings *set) ATTR_NULL(1);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschvoid http_client_deinit(struct http_client **_client);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* switch this client to the current ioloop */
e8a1b62fe4a81b211dcccd1a58b44f254074eab6Stephan Boschstruct ioloop *http_client_switch_ioloop(struct http_client *client);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch/* blocks until all currently submitted requests are handled */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_client_wait(struct http_client *client);
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Bosch/* Returns the total number of pending HTTP requests. */
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschunsigned int
5a37824675033747fcae3fe3fc3c0dd7ef0ca1cdStephan Boschhttp_client_get_pending_request_count(struct http_client *client);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Bosch/*
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Bosch * Client shared context
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Bosch */
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Bosch
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschstruct http_client_context *
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschhttp_client_context_create(const struct http_client_settings *set);
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschvoid http_client_context_ref(struct http_client_context *cctx);
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Boschvoid http_client_context_unref(struct http_client_context **_cctx);
fab1a1c57f467c19c728d2391ff5e5025bb832f7Stephan Bosch
788e61d347adbdb7c9a4d767e381f4bd8a3526b2Timo Sirainen/* Return the default global shared client context, creating it if necessary.
788e61d347adbdb7c9a4d767e381f4bd8a3526b2Timo Sirainen The context is freed automatically at exit. Don't unreference the
788e61d347adbdb7c9a4d767e381f4bd8a3526b2Timo Sirainen returned context. */
788e61d347adbdb7c9a4d767e381f4bd8a3526b2Timo Sirainenstruct http_client_context *http_client_get_global_context(void);
788e61d347adbdb7c9a4d767e381f4bd8a3526b2Timo Sirainen
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#endif