http-client-private.h revision 753c65234187ca52423e7384796a8b0a2d531591
#ifndef HTTP_CLIENT_PRIVATE_H
#define HTTP_CLIENT_PRIVATE_H
#include "connection.h"
#include "http-url.h"
#include "http-client.h"
/*
* Defaults
*/
#define HTTP_DEFAULT_PORT 80
#define HTTPS_DEFAULT_PORT 443
#define HTTP_CLIENT_DEFAULT_BACKOFF_TIME_MSECS (100)
/*
* Types
*/
struct http_client_connection;
struct http_client_peer_pool;
struct http_client_peer_shared;
struct http_client_peer;
struct http_client_queue;
struct http_client_host_shared;
struct http_client_host;
struct http_client_request *);
struct http_client_connection *);
struct http_client_peer *);
struct http_client_peer_shared *);
struct http_client_peer_pool *);
struct http_client_queue *);
struct http_client_host_shared *);
const struct http_client_peer_addr *,
struct http_client_peer_shared *);
const char *, struct http_client_host_shared *);
enum http_client_peer_addr_type {
};
struct http_client_peer_addr {
union {
struct {
const char *https_name; /* TLS SNI */
} tcp;
struct {
const char *path;
} un;
} a;
};
/*
* Objects
*/
struct http_client_request {
unsigned int refcount;
const char *label;
unsigned int id;
struct http_url origin_url;
const char *host_socket;
const char *authority;
struct http_client *client;
struct http_client_host *host;
struct http_client_queue *queue;
struct http_client_peer *peer;
struct http_client_connection *conn;
struct istream *payload_input;
struct ostream *payload_output;
struct timeval release_time;
struct timeval submit_time;
struct timeval first_sent_time;
struct timeval response_time;
struct timeval timeout_time;
unsigned int timeout_msecs;
unsigned int attempt_timeout_msecs;
unsigned int max_attempts;
unsigned int attempts;
unsigned int redirects;
unsigned int delayed_error_status;
const char *delayed_error;
void *context;
void (*destroy_callback)(void *);
void *destroy_context;
enum http_request_state state;
bool have_hdr_authorization:1;
bool have_hdr_body_spec:1;
bool have_hdr_connection:1;
bool have_hdr_date:1;
bool have_hdr_expect:1;
bool have_hdr_host:1;
bool have_hdr_user_agent:1;
bool payload_sync:1;
bool payload_sync_continue:1;
bool payload_chunked:1;
bool payload_wait:1;
bool payload_empty:1;
bool urgent:1;
bool submitted:1;
bool listed:1;
bool connect_tunnel:1;
bool connect_direct:1;
bool ssl_tunnel:1;
bool preserve_exact_reason:1;
};
struct http_client_connection {
struct connection conn;
unsigned int refcount;
struct http_client_peer_pool *ppool;
struct http_client_peer *peer;
char *label;
unsigned int id; // DEBUG: identify parallel connections
int connect_errno;
struct timeval connect_start_timestamp;
struct timeval connected_timestamp;
struct http_client_request *connect_request;
struct ssl_iostream *ssl_iostream;
struct http_response_parser *http_parser;
struct timeout *to_requests;
struct http_client_request *pending_request;
struct istream *incoming_payload;
struct io *io_req_payload;
struct ioloop *last_ioloop;
struct io_wait_timer *io_wait_timer;
/* requests that have been sent, waiting for response */
connection into tunnel */
bool closing:1;
bool disconnected:1;
bool close_indicated:1;
bool debug:1;
};
struct http_client_peer_shared {
unsigned int refcount;
struct http_client_peer_addr addr;
char *addr_name;
char *label;
struct http_client_context *cctx;
struct http_client_peer_pool *pools_list;
struct http_client_peer *peers_list;
unsigned int peers_count;
/* 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;
connections */
};
struct http_client_peer_pool {
unsigned int refcount;
struct http_client_peer_shared *peer;
/* all connections to this peer */
/* pending connections (not ready connecting) */
/* available connections to this peer */
/* distinguishing settings for these connections */
struct ssl_iostream_context *ssl_ctx;
char *rawlog_dir;
struct pcap_output *pcap_output;
};
struct http_client_peer {
unsigned int refcount;
struct http_client_peer_shared *shared;
struct http_client *client;
struct http_client_peer_pool *ppool;
/* queues using this peer */
/* active connections to this peer */
/* zero time-out for consolidating request handling */
struct timeout *to_req_handling;
};
struct http_client_queue {
struct http_client *client;
struct http_client_host *host;
char *name;
struct http_client_peer_addr addr;
char *addr_name;
/* current index in host->ips */
unsigned int ips_connect_idx;
/* 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;
this can be more than one when soft connect timeouts are enabled */
/* currently active peer */
struct http_client_peer *cur_peer;
/* all requests associated to this queue
(ordered by earliest timeout first) */
/* delayed requests waiting to be released after delay */
/* requests pending in queue to be picked up by connections */
};
struct http_client_host_shared {
struct http_client_context *cctx;
char *name;
/* the ip addresses DNS returned for this host */
unsigned int ips_count;
struct timeval ips_timeout;
/* private instance for each client that uses this host */
struct http_client_host *hosts_list;
/* active DNS lookup */
struct dns_lookup *dns_lookup;
/* timeouts */
bool unix_local:1;
bool explicit_ip:1;
};
struct http_client_host {
struct http_client_host_shared *shared;
struct http_client *client;
/* separate queue for each host port */
};
struct http_client {
struct http_client_context *cctx;
struct http_client_settings set;
struct ssl_iostream_context *ssl_ctx;
/* list of failed requests that are waiting for ioloop */
struct timeout *to_failing_requests;
struct http_client_host *hosts_list;
struct http_client_peer *peers_list;
struct http_client_request *requests_list;
unsigned int requests_count;
bool waiting:1;
};
struct http_client_context {
unsigned int refcount;
struct http_client_settings set;
struct dns_client *dns_client;
const char *dns_client_socket_path;
unsigned int dns_ttl_msecs;
unsigned int dns_lookup_timeout_msecs;
struct http_client *clients_list;
struct connection_list *conn_list;
struct http_client_peer_shared *peers_list;
struct http_client_host_shared *unix_host;
struct http_client_host_shared *hosts_list;
};
/*
* Peer address
*/
static inline bool
{
return TRUE;
default:
break;
}
return FALSE;
}
static inline const char *
{
default:
break;
}
return NULL;
}
static inline const char *
{
return t_strdup_printf("[%s]:%u",
}
return t_strdup_printf("%s:%u",
default:
break;
}
i_unreached();
return "";
}
/*
* Request
*/
static inline bool
{
}
const char *
/* Returns FALSE if unrefing destroyed the request entirely */
const struct http_response *response);
struct http_client_peer_addr *addr);
struct http_response *response);
const struct http_client_tunnel *tunnel,
struct http_response *response);
/*
* Connection
*/
struct connection_list *http_client_connection_list_init(void);
struct http_client_connection *
/* Returns FALSE if unrefing destroyed the connection entirely */
struct http_client_connection *conn);
struct http_client_connection *conn);
struct http_client_connection *conn);
struct http_client_connection *conn);
unsigned int
struct http_client_tunnel *tunnel);
struct http_client_peer *peer);
/*
* Peer
*/
/* address */
unsigned int http_client_peer_addr_hash
(const struct http_client_peer_addr *peer1,
/* connection pool */
/* peer (shared) */
const char *
unsigned int
/* peer */
struct http_client_peer *
const struct http_client_peer_addr *addr);
struct http_client_queue *queue);
struct http_client_queue *queue);
struct http_client_queue *queue);
struct http_client_request *
bool no_urgent);
const char *reason);
bool premature);
unsigned int
unsigned int
unsigned int
/*
* Queue
*/
struct http_client_queue *
const struct http_client_peer_addr *addr);
unsigned int
struct http_client_request *req);
struct http_client_request *req);
struct http_client_request *
unsigned int
unsigned int
struct http_client_peer *peer);
struct http_client_peer *peer);
/*
* Host
*/
/* host (shared) */
struct http_client_host_shared **_hshared);
struct http_client_host_shared *hshared);
/* host */
static inline unsigned int
{
}
static inline const struct ip_addr *
unsigned int idx)
{
}
static inline bool
{
}
struct http_client_host *
struct http_client_request *req);
/*
* Client
*/
const char **error_r);
struct http_client_request *req);
struct http_client_request *req);
/*
* Client shared context
*/
#endif