http-server-request.c revision 95e0b82fdff1bb511067d703bb8b67c22f242c38
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Copyright (c) 2013-2014 Dovecot authors, see the included COPYING file */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenhttp_server_request_new(struct http_server_connection *conn)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen pool = pool_alloconly_create("http_message", 4096);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen req = p_new(pool, struct http_server_request, 1);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen DLLIST2_APPEND(&conn->request_queue_head, &conn->request_queue_tail, req);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_ref(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_unref(struct http_server_request **_req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen struct http_server_connection *conn = req->conn;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if (req->state < HTTP_SERVER_REQUEST_STATE_FINISHED) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen req->state = HTTP_SERVER_REQUEST_STATE_ABORTED;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen DLLIST2_REMOVE(&conn->request_queue_head, &conn->request_queue_tail, req);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_set_destroy_callback(struct http_server_request *req,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen void (*callback)(void *),
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_abort(struct http_server_request **_req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen struct http_server_connection *conn = req->conn;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if (req->state < HTTP_SERVER_REQUEST_STATE_FINISHED) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen req->state = HTTP_SERVER_REQUEST_STATE_ABORTED;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen DLLIST2_REMOVE(&conn->request_queue_head, &conn->request_queue_tail, req);
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainenhttp_server_request_get(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenhttp_server_request_get_pool(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_halt_payload(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen i_assert(req->state <= HTTP_SERVER_REQUEST_STATE_QUEUED);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_continue_payload(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen i_assert(req->state <= HTTP_SERVER_REQUEST_STATE_QUEUED);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if (req->req.expect_100_continue && !req->sent_100_continue)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen http_server_connection_send_responses(req->conn);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_ready_to_respond(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen req->state = HTTP_SERVER_REQUEST_STATE_READY_TO_RESPOND;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen http_server_connection_send_responses(req->conn);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_submit_response(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen struct http_server_connection *conn = req->conn;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen i_assert(conn != NULL && req->response != NULL && req->response->submitted);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen req->state = HTTP_SERVER_REQUEST_STATE_SUBMITTED_RESPONSE;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid http_server_request_finished(struct http_server_request *req)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen struct http_server_connection *conn = req->conn;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen struct http_server_response *resp = req->response;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen http_server_tunnel_callback_t tunnel_callback = resp->tunnel_callback;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen i_assert(req->state < HTTP_SERVER_REQUEST_STATE_FINISHED);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen req->state = HTTP_SERVER_REQUEST_STATE_FINISHED;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen DLLIST2_REMOVE(&conn->request_queue_head, &conn->request_queue_tail, req);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if (tunnel_callback == NULL && (req->req.connection_close || resp->close)) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen t_strdup_printf("Server closed connection: %u %s",
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen "Client requested connection close");
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen http_server_connection_tunnel(&conn, tunnel_callback, tunnel_context);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenhttp_server_request_fail_full(struct http_server_request *req,
f8da06de93e28b5d3e039a427cdde7e1e15daec8Timo Sirainen unsigned int status, const char *reason, bool close)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen resp = http_server_response_create(req, status, reason);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen (resp, "Content-Type", "text/plain; charset=utf-8");
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen (resp, (const unsigned char *)reason, strlen(reason));