struct http_client_host_shared;
struct http_client_host;
-ARRAY_DEFINE_TYPE(http_client_request,
- struct http_client_request *);
-ARRAY_DEFINE_TYPE(http_client_connection,
- struct http_client_connection *);
-ARRAY_DEFINE_TYPE(http_client_peer,
- struct http_client_peer *);
-ARRAY_DEFINE_TYPE(http_client_peer_shared,
- struct http_client_peer_shared *);
-ARRAY_DEFINE_TYPE(http_client_peer_pool,
- struct http_client_peer_pool *);
-ARRAY_DEFINE_TYPE(http_client_queue,
- struct http_client_queue *);
-ARRAY_DEFINE_TYPE(http_client_host,
- struct http_client_host_shared *);
+ARRAY_DEFINE_TYPE(http_client_request, struct http_client_request *);
+ARRAY_DEFINE_TYPE(http_client_connection, struct http_client_connection *);
+ARRAY_DEFINE_TYPE(http_client_peer, struct http_client_peer *);
+ARRAY_DEFINE_TYPE(http_client_peer_shared, struct http_client_peer_shared *);
+ARRAY_DEFINE_TYPE(http_client_peer_pool, struct http_client_peer_pool *);
+ARRAY_DEFINE_TYPE(http_client_queue, struct http_client_queue *);
+ARRAY_DEFINE_TYPE(http_client_host, struct http_client_host_shared *);
HASH_TABLE_DEFINE_TYPE(http_client_peer_shared,
- const struct http_client_peer_addr *,
- struct http_client_peer_shared *);
-HASH_TABLE_DEFINE_TYPE(http_client_host_shared,
- const char *, struct http_client_host_shared *);
+ const struct http_client_peer_addr *,
+ struct http_client_peer_shared *);
+HASH_TABLE_DEFINE_TYPE(http_client_host_shared, const char *,
+ struct http_client_host_shared *);
enum http_client_peer_addr_type {
HTTP_CLIENT_PEER_ADDR_HTTP = 0,
struct ioloop *last_ioloop;
struct io_wait_timer *io_wait_timer;
- /* requests that have been sent, waiting for response */
+ /* Requests that have been sent, waiting for response */
ARRAY_TYPE(http_client_request) request_wait_list;
- bool connected:1; /* connection is connected */
- bool tunneling:1; /* last sent request turns this
+ bool connected:1; /* Connection is connected */
+ bool tunneling:1; /* Last sent request turns this
connection into tunnel */
- bool connect_succeeded:1; /* connection succeeded including SSL */
- bool connect_failed:1; /* connection failed */
- bool lost_prematurely:1; /* lost connection before receiving any data */
+ bool connect_succeeded:1; /* Connection succeeded including SSL */
+ bool connect_failed:1; /* Connection failed */
+ bool lost_prematurely:1; /* Lost connection before receiving any data */
bool closing:1;
bool disconnected:1;
bool close_indicated:1;
- bool output_locked:1; /* output is locked; no pipelining */
- bool output_broken:1; /* output is broken; no more requests */
- bool in_req_callback:1; /* performing request callback (busy) */
+ bool output_locked:1; /* Output is locked; no pipelining */
+ bool output_broken:1; /* Output is broken; no more requests */
+ bool in_req_callback:1; /* Performing request callback (busy) */
bool debug:1;
};
struct http_client_peer *peers_list;
unsigned int peers_count;
- /* connection retry */
+ /* Connection retry */
struct timeval last_failure;
struct timeout *to_backoff;
unsigned int backoff_initial_time_msecs;
unsigned int backoff_current_time_msecs;
unsigned int backoff_max_time_msecs;
- bool no_payload_sync:1; /* expect: 100-continue failed before */
- bool seen_100_response:1;/* expect: 100-continue succeeded before */
- bool allows_pipelining:1;/* peer is known to allow persistent
- connections */
+ bool no_payload_sync:1; /* Expect: 100-continue failed before */
+ bool seen_100_response:1; /* Expect: 100-continue succeeded before */
+ bool allows_pipelining:1; /* Peer is known to allow persistent
+ connections */
};
struct http_client_peer_pool {
struct http_client_peer_pool *prev, *next;
struct event *event;
- /* all connections to this peer */
+ /* All connections to this peer */
ARRAY_TYPE(http_client_connection) conns;
- /* pending connections (not ready connecting) */
+ /* Pending connections (not ready connecting) */
ARRAY_TYPE(http_client_connection) pending_conns;
- /* available connections to this peer */
+ /* Available connections to this peer */
ARRAY_TYPE(http_client_connection) idle_conns;
- /* distinguishing settings for these connections */
+ /* Distinguishing settings for these connections */
struct ssl_iostream_context *ssl_ctx;
char *rawlog_dir;
struct pcap_output *pcap_output;
- bool destroyed:1; /* peer pool is being destroyed */
+ bool destroyed:1; /* Peer pool is being destroyed */
};
struct http_client_peer {
struct http_client_peer_pool *ppool;
struct event *event;
- /* queues using this peer */
+ /* Queues using this peer */
ARRAY_TYPE(http_client_queue) queues;
- /* active connections to this peer */
+ /* Active connections to this peer */
ARRAY_TYPE(http_client_connection) conns;
- /* pending connections (not ready connecting) */
+ /* Pending connections (not ready connecting) */
ARRAY_TYPE(http_client_connection) pending_conns;
- /* zero time-out for consolidating request handling */
+ /* Zero time-out for consolidating request handling */
struct timeout *to_req_handling;
- bool connect_failed:1; /* last connection attempt failed */
- bool connect_backoff:1; /* peer is waiting for backoff timout*/
- bool disconnected:1; /* peer is already disconnected */
- bool handling_requests:1;/* currently running request handler */
+ bool connect_failed:1; /* Last connection attempt failed */
+ bool connect_backoff:1; /* Peer is waiting for backoff timout*/
+ bool disconnected:1; /* Peer is already disconnected */
+ bool handling_requests:1; /* Currently running request handler */
};
struct http_client_queue {
struct http_client_peer_addr addr;
char *addr_name;
- /* current index in host->ips */
+ /* Current index in host->ips */
unsigned int ips_connect_idx;
- /* the first IP that started the current round of connection attempts.
+ /* The first IP that started the current round of connection attempts.
initially 0, and later set to the ip index of the last successful
connected IP */
unsigned int ips_connect_start_idx;
struct timeval first_connect_time;
unsigned int connect_attempts;
- /* peers we are trying to connect to;
+ /* Peers we are trying to connect to;
this can be more than one when soft connect timeouts are enabled */
ARRAY_TYPE(http_client_peer) pending_peers;
- /* currently active peer */
+ /* Currently active peer */
struct http_client_peer *cur_peer;
- /* all requests associated to this queue
+ /* All requests associated to this queue
(ordered by earliest timeout first) */
ARRAY_TYPE(http_client_request) requests;
- /* delayed requests waiting to be released after delay */
+ /* Delayed requests waiting to be released after delay */
ARRAY_TYPE(http_client_request) delayed_requests;
- /* requests pending in queue to be picked up by connections */
+ /* Requests pending in queue to be picked up by connections */
ARRAY_TYPE(http_client_request) queued_requests, queued_urgent_requests;
struct timeout *to_connect, *to_request, *to_delayed;
char *name;
struct event *event;
- /* the ip addresses DNS returned for this host */
+ /* The ip addresses DNS returned for this host */
unsigned int ips_count;
struct ip_addr *ips;
struct timeval ips_timeout;
- /* private instance for each client that uses this host */
+ /* Private instance for each client that uses this host */
struct http_client_host *hosts_list;
- /* active DNS lookup */
+ /* Active DNS lookup */
struct dns_lookup *dns_lookup;
- /* timeouts */
+ /* Timeouts */
struct timeout *to_idle;
- bool destroyed:1; /* shared host object is being destroyed */
+ bool destroyed:1; /* Shared host object is being destroyed */
bool unix_local:1;
bool explicit_ip:1;
};
struct http_client *client;
struct http_client_host *client_prev, *client_next;
- /* separate queue for each host port */
+ /* Separate queue for each host port */
ARRAY_TYPE(http_client_queue) queues;
};
struct ioloop *ioloop;
struct ssl_iostream_context *ssl_ctx;
- /* list of failed requests that are waiting for ioloop */
+ /* List of failed requests that are waiting for ioloop */
ARRAY(struct http_client_request *) delayed_failing_requests;
struct timeout *to_failing_requests;
case HTTP_CLIENT_PEER_ADDR_RAW:
if (addr->a.tcp.ip.family == AF_INET6) {
return t_strdup_printf("[%s]:%u",
- net_ip2addr(&addr->a.tcp.ip), addr->a.tcp.port);
+ net_ip2addr(&addr->a.tcp.ip),
+ addr->a.tcp.port);
}
return t_strdup_printf("%s:%u",
- net_ip2addr(&addr->a.tcp.ip), addr->a.tcp.port);
+ net_ip2addr(&addr->a.tcp.ip),
+ addr->a.tcp.port);
case HTTP_CLIENT_PEER_ADDR_UNIX:
return t_strdup_printf("unix:%s", addr->a.un.path);
default:
return (req->host_url != &req->origin_url);
}
-const char *
-http_client_request_label(struct http_client_request *req);
+const char *http_client_request_label(struct http_client_request *req);
void http_client_request_ref(struct http_client_request *req);
/* Returns FALSE if unrefing destroyed the request entirely */
void http_client_request_destroy(struct http_client_request **_req);
void http_client_request_get_peer_addr(const struct http_client_request *req,
- struct http_client_peer_addr *addr);
+ struct http_client_peer_addr *addr);
enum http_response_payload_type
http_client_request_get_payload_type(struct http_client_request *req);
-int http_client_request_send(struct http_client_request *req,
- bool pipelined);
+int http_client_request_send(struct http_client_request *req, bool pipelined);
int http_client_request_send_more(struct http_client_request *req,
bool pipelined);
+
bool http_client_request_callback(struct http_client_request *req,
- struct http_response *response);
+ struct http_response *response);
void http_client_request_connect_callback(struct http_client_request *req,
- const struct http_client_tunnel *tunnel,
- struct http_response *response);
+ const struct http_client_tunnel *tunnel,
+ struct http_response *response);
+
void http_client_request_resubmit(struct http_client_request *req);
void http_client_request_retry(struct http_client_request *req,
- unsigned int status, const char *error);
+ unsigned int status, const char *error);
void http_client_request_error_delayed(struct http_client_request **_req);
void http_client_request_error(struct http_client_request **req,
- unsigned int status, const char *error);
+ unsigned int status, const char *error);
void http_client_request_redirect(struct http_client_request *req,
- unsigned int status, const char *location);
+ unsigned int status, const char *location);
void http_client_request_finish(struct http_client_request *req);
/*
void http_client_connection_check_idle(struct http_client_connection *conn);
void http_client_connection_switch_ioloop(struct http_client_connection *conn);
void http_client_connection_start_tunnel(struct http_client_connection **_conn,
- struct http_client_tunnel *tunnel);
+ struct http_client_tunnel *tunnel);
void http_client_connection_lost_peer(struct http_client_connection *conn);
void http_client_connection_claim_idle(struct http_client_connection *conn,
- struct http_client_peer *peer);
+ struct http_client_peer *peer);
/*
* Peer
/* address */
-unsigned int http_client_peer_addr_hash
- (const struct http_client_peer_addr *peer) ATTR_PURE;
-int http_client_peer_addr_cmp
- (const struct http_client_peer_addr *peer1,
- const struct http_client_peer_addr *peer2) ATTR_PURE;
+unsigned int
+http_client_peer_addr_hash(const struct http_client_peer_addr *peer) ATTR_PURE;
+int http_client_peer_addr_cmp(const struct http_client_peer_addr *peer1,
+ const struct http_client_peer_addr *peer2)
+ ATTR_PURE;
/* connection pool */
void http_client_peer_shared_unref(struct http_client_peer_shared **_pshared);
void http_client_peer_shared_close(struct http_client_peer_shared **_pshared);
-void http_client_peer_shared_switch_ioloop(struct http_client_peer_shared *pshared);
+void http_client_peer_shared_switch_ioloop(
+ struct http_client_peer_shared *pshared);
unsigned int
-http_client_peer_shared_max_connections(struct http_client_peer_shared *pshared);
+http_client_peer_shared_max_connections(
+ struct http_client_peer_shared *pshared);
/* peer */
struct http_client_peer *
http_client_peer_get(struct http_client *client,
- const struct http_client_peer_addr *addr);
+ const struct http_client_peer_addr *addr);
void http_client_peer_ref(struct http_client_peer *peer);
bool http_client_peer_unref(struct http_client_peer **_peer);
void http_client_peer_close(struct http_client_peer **_peer);
bool http_client_peer_have_queue(struct http_client_peer *peer,
- struct http_client_queue *queue);
+ struct http_client_queue *queue);
void http_client_peer_link_queue(struct http_client_peer *peer,
- struct http_client_queue *queue);
+ struct http_client_queue *queue);
void http_client_peer_unlink_queue(struct http_client_peer *peer,
- struct http_client_queue *queue);
+ struct http_client_queue *queue);
struct http_client_request *
- http_client_peer_claim_request(struct http_client_peer *peer,
- bool no_urgent);
+http_client_peer_claim_request(struct http_client_peer *peer, bool no_urgent);
void http_client_peer_trigger_request_handler(struct http_client_peer *peer);
void http_client_peer_connection_success(struct http_client_peer *peer);
void http_client_peer_connection_failure(struct http_client_peer *peer,
const char *reason);
void http_client_peer_connection_lost(struct http_client_peer *peer,
- bool premature);
+ bool premature);
bool http_client_peer_is_connected(struct http_client_peer *peer);
unsigned int
http_client_peer_idle_connections(struct http_client_peer *peer);
struct http_client_queue *
http_client_queue_get(struct http_client_host *host,
- const struct http_client_peer_addr *addr);
+ const struct http_client_peer_addr *addr);
void http_client_queue_free(struct http_client_queue *queue);
void http_client_queue_connection_setup(struct http_client_queue *queue);
unsigned int
http_client_queue_host_lookup_done(struct http_client_queue *queue);
-void http_client_queue_host_lookup_failure(
- struct http_client_queue *queue, const char *error);
+void http_client_queue_host_lookup_failure(struct http_client_queue *queue,
+ const char *error);
void http_client_queue_submit_request(struct http_client_queue *queue,
- struct http_client_request *req);
+ struct http_client_request *req);
void http_client_queue_drop_request(struct http_client_queue *queue,
- struct http_client_request *req);
+ struct http_client_request *req);
struct http_client_request *
http_client_queue_claim_request(struct http_client_queue *queue,
- const struct http_client_peer_addr *addr, bool no_urgent);
+ const struct http_client_peer_addr *addr,
+ bool no_urgent);
unsigned int
http_client_queue_requests_pending(struct http_client_queue *queue,
- unsigned int *num_urgent_r) ATTR_NULL(2);
-unsigned int
-http_client_queue_requests_active(struct http_client_queue *queue);
+ unsigned int *num_urgent_r) ATTR_NULL(2);
+unsigned int http_client_queue_requests_active(struct http_client_queue *queue);
void http_client_queue_connection_success(struct http_client_queue *queue,
- struct http_client_peer *peer);
+ struct http_client_peer *peer);
void http_client_queue_connection_failure(struct http_client_queue *queue,
- struct http_client_peer *peer, const char *reason);
+ struct http_client_peer *peer,
+ const char *reason);
void http_client_queue_peer_disconnected(struct http_client_queue *queue,
- struct http_client_peer *peer);
+ struct http_client_peer *peer);
void http_client_queue_switch_ioloop(struct http_client_queue *queue);
/*
/* host (shared) */
-void http_client_host_shared_free(
- struct http_client_host_shared **_hshared);
+void http_client_host_shared_free(struct http_client_host_shared **_hshared);
void http_client_host_shared_switch_ioloop(
struct http_client_host_shared *hshared);
}
static inline const struct ip_addr *
-http_client_host_get_ip(struct http_client_host *host,
- unsigned int idx)
+http_client_host_get_ip(struct http_client_host *host, unsigned int idx)
{
i_assert(idx < host->shared->ips_count);
return &host->shared->ips[idx];
struct http_client_host *
http_client_host_get(struct http_client *client,
- const struct http_url *host_url);
+ const struct http_url *host_url);
void http_client_host_free(struct http_client_host **_host);
void http_client_host_submit_request(struct http_client_host *host,
- struct http_client_request *req);
+ struct http_client_request *req);
void http_client_host_switch_ioloop(struct http_client_host *host);
void http_client_host_check_idle(struct http_client_host *host);
int http_client_host_refresh(struct http_client_host *host);
bool http_client_host_get_ip_idx(struct http_client_host *host,
- const struct ip_addr *ip, unsigned int *idx_r);
+ const struct ip_addr *ip, unsigned int *idx_r);
/*
* Client
*/
-int http_client_init_ssl_ctx(struct http_client *client,
- const char **error_r);
+int http_client_init_ssl_ctx(struct http_client *client, const char **error_r);
void http_client_delay_request_error(struct http_client *client,
- struct http_client_request *req);
+ struct http_client_request *req);
void http_client_remove_request_error(struct http_client *client,
- struct http_client_request *req);
+ struct http_client_request *req);
/*
* Client shared context