]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: server: Allow holding only a reference to the request payload stream, rathe...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 28 Mar 2017 22:17:50 +0000 (00:17 +0200)
committerGitLab <gitlab@git.dovecot.net>
Tue, 4 Jul 2017 12:56:17 +0000 (15:56 +0300)
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.

src/lib-http/http-server-connection.c
src/lib-http/http-server.h

index 5144b4e21918dc924000ff0ce3a8657f1ba768a8..16d5248782eff8ee28716ccf8efdd2dcfd1a85f0 100644 (file)
@@ -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);
index 59e0555831c92b2bc0ca41bdcb32b43c8ad34be5..688714fb3a38e7d8a45bda87b47256cbbdcf5aaa 100644 (file)
@@ -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()