From: Stephan Bosch Date: Tue, 28 Mar 2017 22:17:50 +0000 (+0200) Subject: lib-http: server: Allow holding only a reference to the request payload stream, rathe... X-Git-Tag: 2.3.0.rc1~1317 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49c232ae035319ea0cedae3828d2e750560e6533;p=thirdparty%2Fdovecot%2Fcore.git lib-http: server: Allow holding only a reference to the request payload stream, rather than the request itself. This mimics the http-client behavior in this case. It makes the implementation of the background payload handling API in subsequent commits a little simpler. --- diff --git a/src/lib-http/http-server-connection.c b/src/lib-http/http-server-connection.c index 5144b4e219..16d5248782 100644 --- a/src/lib-http/http-server-connection.c +++ b/src/lib-http/http-server-connection.c @@ -280,8 +280,6 @@ static void http_server_payload_destroyed(struct http_server_request *req) static void http_server_connection_request_callback( struct http_server_connection *conn, struct http_server_request *req) { - unsigned int old_refcount = req->refcount; - /* CONNECT method */ if (strcmp(req->req.method, "CONNECT") == 0) { if (conn->callbacks->handle_connect_request == NULL) { @@ -303,10 +301,6 @@ static void http_server_connection_request_callback( } conn->callbacks->handle_request(conn->context, req); } - - i_assert((req->response != NULL && - req->response->submitted) || - req->refcount > old_refcount); } static bool @@ -314,7 +308,9 @@ http_server_connection_handle_request(struct http_server_connection *conn, struct http_server_request *req) { const struct http_server_settings *set = &conn->server->set; + unsigned int old_refcount, new_refcount; struct istream *payload; + bool payload_destroyed = FALSE; i_assert(!conn->in_req_callback); i_assert(conn->incoming_payload == NULL); @@ -345,6 +341,7 @@ http_server_connection_handle_request(struct http_server_connection *conn, our one before calling it */ http_server_connection_input_halt(conn); + old_refcount = req->refcount; conn->in_req_callback = TRUE; http_server_connection_request_callback(conn, req); if (conn->closed) { @@ -352,6 +349,7 @@ http_server_connection_handle_request(struct http_server_connection *conn, return FALSE; } conn->in_req_callback = FALSE; + new_refcount = req->refcount; if (req->req.payload != NULL) { /* send 100 Continue when appropriate */ @@ -369,6 +367,7 @@ http_server_connection_handle_request(struct http_server_connection *conn, if (conn->to_input != NULL) { /* already finished reading the payload */ http_server_payload_finished(conn); + payload_destroyed = TRUE; } } @@ -381,6 +380,10 @@ http_server_connection_handle_request(struct http_server_connection *conn, http_server_request_submit_response(req); } + i_assert(!payload_destroyed || + new_refcount > old_refcount || + (req->response != NULL && req->response->submitted)); + if (conn->incoming_payload == NULL) { if (conn->conn.io == NULL && conn->to_input == NULL) http_server_connection_input_resume(conn); diff --git a/src/lib-http/http-server.h b/src/lib-http/http-server.h index 59e0555831..688714fb3a 100644 --- a/src/lib-http/http-server.h +++ b/src/lib-http/http-server.h @@ -228,7 +228,8 @@ struct http_server_callbacks { The response is sent either with http_server_request_fail*() or http_server_response_submit*(). For simple requests you can send the response back immediately. If you can't do that, you'll need to - reference the request. Then the code flow usually goes like this: + reference the request (or the request payload input stream). Then the + code flow usually goes like this: - http_server_request_set_destroy_callback(destroy_callback) - http_server_request_ref()