]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Make sure output is used only when valid in http_client_request_sen...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Feb 2018 13:54:47 +0000 (14:54 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 08:42:26 +0000 (10:42 +0200)
src/lib-http/http-client-request.c

index d6b3d6c21efa03b719bf9abac94e635ffca33d70..1d461ea22ec5f069123ca2cab058b770a9e4fe9e 100644 (file)
@@ -1150,7 +1150,6 @@ static int http_client_request_send_real(struct http_client_request *req,
 {
        const struct http_client_settings *set = &req->client->set;
        struct http_client_connection *conn = req->conn;
-       struct ostream *output = conn->conn.output;
        string_t *rtext = t_str_new(256);
        struct const_iovec iov[3];
        int ret = 0;
@@ -1210,7 +1209,7 @@ static int http_client_request_send_real(struct http_client_request *req,
                if (!req->have_hdr_body_spec)
                        str_append(rtext, "Transfer-Encoding: chunked\r\n");
                req->payload_output =
-                       http_transfer_chunked_ostream_create(output);
+                       http_transfer_chunked_ostream_create(conn->conn.output);
        } else if (req->payload_input != NULL ||
                req->payload_empty ||
                strcasecmp(req->method, "POST") == 0 ||
@@ -1224,8 +1223,8 @@ static int http_client_request_send_real(struct http_client_request *req,
                                req->payload_size);
                }
                if (req->payload_input != NULL) {
-                       req->payload_output = output;
-                       o_stream_ref(output);
+                       req->payload_output = conn->conn.output;
+                       o_stream_ref(conn->conn.output);
                }
        }
        if (!req->have_hdr_connection &&
@@ -1263,8 +1262,8 @@ static int http_client_request_send_real(struct http_client_request *req,
        req->sent_global_ioloop_usecs = ioloop_global_wait_usecs;
        req->sent_http_ioloop_usecs =
                io_wait_timer_get_usecs(req->conn->io_wait_timer);
-       o_stream_cork(output);
-       if (o_stream_sendv(output, iov, N_ELEMENTS(iov)) < 0) {
+       o_stream_cork(conn->conn.output);
+       if (o_stream_sendv(conn->conn.output, iov, N_ELEMENTS(iov)) < 0) {
                http_client_connection_handle_output_error(conn);
                ret = -1;
        } else {
@@ -1285,7 +1284,8 @@ static int http_client_request_send_real(struct http_client_request *req,
                        conn->output_locked = FALSE;
                }
        }
-       if (ret >= 0 && o_stream_uncork_flush(output) < 0) {
+       if (ret >= 0 && conn->conn.output != NULL &&
+           o_stream_uncork_flush(conn->conn.output) < 0) {
                http_client_connection_handle_output_error(conn);
                ret = -1;
        }