http-server-private.h revision 3cda61e4ccaa1192528776d315f7ed5534315cb0
76b43e4417bab52e913da39b5f5bc2a130d3f149Timo Sirainen#ifndef HTTP_SERVER_PRIVATE_H
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#define HTTP_SERVER_PRIVATE_H
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#include "connection.h"
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#include "iostream-pump.h"
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#include "http-server.h"
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#include "llist.h"
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainenstruct http_server_payload_handler;
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainenstruct http_server_request;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstruct http_server_connection;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen/*
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen * Defaults
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen */
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#define HTTP_SERVER_REQUEST_MAX_TARGET_LENGTH 4096
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen/*
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen * Types
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen */
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainenenum http_server_request_state {
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* New request; request header is still being parsed. */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_NEW = 0,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Queued request; callback to request handler executing. */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_QUEUED,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Reading request payload; request handler still needs to read more
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen payload. */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_PAYLOAD_IN,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* This request is being processed; request payload is fully read, but no
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen response is yet submitted */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_PROCESSING,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* A response is submitted for this request. If not all request payload
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen was read by the handler, it is first skipped on the input.
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_SUBMITTED_RESPONSE,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Request is ready for response; a response is submitted and the request
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen payload is fully read */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_READY_TO_RESPOND,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* The response for the request is sent (apart from payload) */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_SENT_RESPONSE,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Sending response payload to client */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_PAYLOAD_OUT,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Request is finished; still lingering due to references */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_FINISHED,
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Request is aborted; still lingering due to references */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen HTTP_SERVER_REQUEST_STATE_ABORTED
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen};
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen/*
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen * Objects
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen */
ebfbf5d78dcf95e8b176429f4b5b0694eb4e17d5Timo Sirainen
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainenstruct http_server_payload_handler {
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen struct http_server_request *req;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen void (*switch_ioloop)(struct http_server_payload_handler *handler);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen void (*destroy)(struct http_server_payload_handler *handler);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool in_callback:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen};
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstruct http_server_response {
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct http_server_request *request;
88187ee880b4829443e0d55ea7d145d9d5880217Timo Sirainen
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen unsigned int status;
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen const char *reason;
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen string_t *headers;
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen time_t date;
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen ARRAY_TYPE(http_auth_challenge) auth_challenges;
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen
ebfbf5d78dcf95e8b176429f4b5b0694eb4e17d5Timo Sirainen struct istream *payload_input;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen uoff_t payload_size, payload_offset;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct ostream *payload_output;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct ostream *blocking_output;
ebfbf5d78dcf95e8b176429f4b5b0694eb4e17d5Timo Sirainen
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen http_server_tunnel_callback_t tunnel_callback;
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen void *tunnel_context;
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen bool have_hdr_connection:1;
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen bool have_hdr_date:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool have_hdr_body_spec:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool payload_chunked:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool payload_blocking:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool payload_direct:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool payload_corked:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool submitted:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen};
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstruct http_server_request {
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct http_request req;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen pool_t pool;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen unsigned int refcount;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen unsigned int id;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen int callback_refcount;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen enum http_server_request_state state;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen struct http_server_request *prev, *next;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct http_server *server;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct http_server_connection *conn;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct istream *payload_input;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct http_server_response *response;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen void (*destroy_callback)(void *);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen void *destroy_context;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen bool payload_halted:1;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen bool sent_100_continue:1;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen bool delay_destroy:1;
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen bool destroy_pending:1;
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen bool failed:1;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen bool connection_close:1;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen};
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenstruct http_server_connection {
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct connection conn;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct http_server *server;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen unsigned int refcount;
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen const struct http_server_callbacks *callbacks;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen void *context;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen unsigned int id; // DEBUG
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct timeout *to_input, *to_idle;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct ssl_iostream *ssl_iostream;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct http_request_parser *http_parser;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct http_server_request *request_queue_head, *request_queue_tail;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen unsigned int request_queue_count;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct istream *incoming_payload;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct http_server_payload_handler *payload_handler;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct io *io_resp_payload;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen char *disconnect_reason;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct http_server_stats stats;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen bool ssl:1;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen bool closed:1;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen bool close_indicated:1;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen bool input_broken:1;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen bool output_locked:1;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen bool in_req_callback:1; /* performing request callback (busy) */
fcde781c3ceb470c8dff34a68df19c69f93bcec9Timo Sirainen bool switching_ioloop:1; /* in the middle of switching ioloop */
fcde781c3ceb470c8dff34a68df19c69f93bcec9Timo Sirainen};
fcde781c3ceb470c8dff34a68df19c69f93bcec9Timo Sirainen
fcde781c3ceb470c8dff34a68df19c69f93bcec9Timo Sirainenstruct http_server {
fcde781c3ceb470c8dff34a68df19c69f93bcec9Timo Sirainen pool_t pool;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct http_server_settings set;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct ioloop *ioloop;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct ssl_iostream_context *ssl_ctx;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct connection_list *conn_list;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen bool shutting_down:1; /* shutting down server */
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen};
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen/*
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen * Response
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen */
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenvoid http_server_response_free(struct http_server_response *resp);
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenint http_server_response_send(struct http_server_response *resp);
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenint http_server_response_send_more(struct http_server_response *resp);
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
fcde781c3ceb470c8dff34a68df19c69f93bcec9Timo Sirainen/*
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen * Request
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen */
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline const char *
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenhttp_server_request_label(struct http_server_request *req)
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen{
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen if (req->req.method == NULL) {
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen if (req->req.target_raw == NULL)
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen return t_strdup_printf("[Req%u: <NEW>]", req->id);
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen return t_strdup_printf("[Req%u: %s <INCOMPLETE>]",
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen req->id, req->req.method);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen }
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen return t_strdup_printf("[Req%u: %s %s]", req->id,
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen req->req.method, req->req.target_raw);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen}
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline bool
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenhttp_server_request_is_new(struct http_server_request *req)
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen{
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen return (req->state == HTTP_SERVER_REQUEST_STATE_NEW);
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen}
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenstatic inline bool
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenhttp_server_request_version_equals(struct http_server_request *req,
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen unsigned int major, unsigned int minor) {
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen return (req->req.version_major == major && req->req.version_minor == minor);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen}
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenstruct http_server_request *
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenhttp_server_request_new(struct http_server_connection *conn);
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenvoid http_server_request_destroy(struct http_server_request **_req);
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenvoid http_server_request_abort(struct http_server_request **_req,
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen const char *reason) ATTR_NULL(2);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenbool http_server_request_is_complete(struct http_server_request *req);
916221f976af0ed8b397f06f4f381c0ac0be3b86Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_request_halt_payload(struct http_server_request *req);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_request_continue_payload(struct http_server_request *req);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenvoid http_server_request_submit_response(struct http_server_request *req);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_request_ready_to_respond(struct http_server_request *req);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenvoid http_server_request_finished(struct http_server_request *req);
916221f976af0ed8b397f06f4f381c0ac0be3b86Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen/* payload handler */
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_payload_handler_destroy(
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct http_server_payload_handler **_handler);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_payload_handler_switch_ioloop(
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct http_server_payload_handler *handler);
916221f976af0ed8b397f06f4f381c0ac0be3b86Timo Sirainen
0fd1e7da973b92e0544ac5783eac2bac6567add1Timo Sirainen/*
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen * connection
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen */
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline const char *
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenhttp_server_connection_label(struct http_server_connection *conn)
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen{
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen return conn->conn.name;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen}
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline void
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenhttp_server_connection_add_request(struct http_server_connection *conn,
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct http_server_request *sreq)
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen{
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen DLLIST2_APPEND(&conn->request_queue_head, &conn->request_queue_tail, sreq);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen conn->request_queue_count++;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen}
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenstatic inline void
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenhttp_server_connection_remove_request(struct http_server_connection *conn,
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen struct http_server_request *sreq)
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen{
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen DLLIST2_REMOVE(&conn->request_queue_head, &conn->request_queue_tail, sreq);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen conn->request_queue_count--;
}
struct connection_list *http_server_connection_list_init(void);
bool http_server_connection_shut_down(struct http_server_connection *conn);
void http_server_connection_switch_ioloop(struct http_server_connection *conn);
void http_server_connection_handle_output_error(
struct http_server_connection *conn);
void http_server_connection_trigger_responses(
struct http_server_connection *conn);
int http_server_connection_flush(struct http_server_connection *conn);
int http_server_connection_output(struct http_server_connection *conn);
void http_server_connection_tunnel(struct http_server_connection **_conn,
http_server_tunnel_callback_t callback, void *context);
int http_server_connection_discard_payload(
struct http_server_connection *conn);
bool http_server_connection_pending_payload(
struct http_server_connection *conn);
#endif