5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch#define HTTP_SERVER_REQUEST_MAX_TARGET_LENGTH 4096
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* New request; request header is still being parsed. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* Queued request; callback to request handler executing. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* Reading request payload; request handler still needs to read more
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* This request is being processed; request payload is fully read, but no
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch response is yet submitted */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* A response is submitted for this request. If not all request payload
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch was read by the handler, it is first skipped on the input.
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* Request is ready for response; a response is submitted and the request
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch payload is fully read */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* The response for the request is sent (apart from payload) */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* Sending response payload to client */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* Request is finished; still lingering due to references */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* Request is aborted; still lingering due to references */
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch void (*switch_ioloop)(struct http_server_payload_handler *handler);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch void (*destroy)(struct http_server_payload_handler *handler);
564e117d86ce5b659f9b9570edddc566f9ebb5dfStephan Bosch ARRAY_TYPE(http_auth_challenge) auth_challenges;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch http_server_tunnel_callback_t tunnel_callback;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch const struct http_server_callbacks *callbacks;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct http_server_request *request_queue_head, *request_queue_tail;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch struct http_server_payload_handler *payload_handler;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool in_req_callback:1; /* performing request callback (busy) */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool switching_ioloop:1; /* in the middle of switching ioloop */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool shutting_down:1; /* shutting down server */
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschvoid http_server_response_free(struct http_server_response *resp);
3cda61e4ccaa1192528776d315f7ed5534315cb0Stephan Boschint http_server_response_send(struct http_server_response *resp);
3cda61e4ccaa1192528776d315f7ed5534315cb0Stephan Boschint http_server_response_send_more(struct http_server_response *resp);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic inline const char *
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschhttp_server_request_label(struct http_server_request *req)
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch return t_strdup_printf("[Req%u: <NEW>]", req->id);
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch return t_strdup_printf("[Req%u: %s <INCOMPLETE>]",
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch return t_strdup_printf("[Req%u: %s %s]", req->id,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstatic inline bool
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschhttp_server_request_is_new(struct http_server_request *req)
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch return (req->state == HTTP_SERVER_REQUEST_STATE_NEW);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstatic inline bool
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschhttp_server_request_version_equals(struct http_server_request *req,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch return (req->req.version_major == major && req->req.version_minor == minor);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschhttp_server_request_new(struct http_server_connection *conn);
faa8995f1d300e7a8917407a52bbd1b98e10bf25Timo Sirainenvoid http_server_request_destroy(struct http_server_request **_req);
ee2633056e67353157bfbce4d9e0d1c3ceaa627aStephan Boschvoid http_server_request_abort(struct http_server_request **_req,
9ec9b6f85c8fbe67bfac523a5e3d33d34f72dddcStephan Boschbool http_server_request_is_complete(struct http_server_request *req);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid http_server_request_halt_payload(struct http_server_request *req);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid http_server_request_continue_payload(struct http_server_request *req);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid http_server_request_submit_response(struct http_server_request *req);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid http_server_request_ready_to_respond(struct http_server_request *req);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid http_server_request_finished(struct http_server_request *req);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch/* payload handler */
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch struct http_server_payload_handler **_handler);
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschvoid http_server_payload_handler_switch_ioloop(
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstatic inline const char *
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschhttp_server_connection_label(struct http_server_connection *conn)
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstatic inline void
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschhttp_server_connection_add_request(struct http_server_connection *conn,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch DLLIST2_APPEND(&conn->request_queue_head, &conn->request_queue_tail, sreq);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstatic inline void
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschhttp_server_connection_remove_request(struct http_server_connection *conn,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch DLLIST2_REMOVE(&conn->request_queue_head, &conn->request_queue_tail, sreq);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstruct connection_list *http_server_connection_list_init(void);
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Boschbool http_server_connection_shut_down(struct http_server_connection *conn);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid http_server_connection_switch_ioloop(struct http_server_connection *conn);
e4b70fb422bf53ddf017948de26b5ea5a1a262fbStephan Boschvoid http_server_connection_handle_output_error(
ee2633056e67353157bfbce4d9e0d1c3ceaa627aStephan Boschint http_server_connection_flush(struct http_server_connection *conn);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschint http_server_connection_output(struct http_server_connection *conn);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid http_server_connection_tunnel(struct http_server_connection **_conn,