]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Fix aborting a request that has a delayed error.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 26 Mar 2017 17:08:18 +0000 (19:08 +0200)
committerGitLab <gitlab@git.dovecot.net>
Sun, 26 Mar 2017 18:16:17 +0000 (21:16 +0300)
Caused by recent changes in delayed error handling.

src/lib-http/http-client-request.c
src/lib-http/test-http-client-errors.c

index 4ee7ad582e574ad45b1af8e91e8fd84f85447314..f39858683b061a404b6af4092b96a10ab66f85e6 100644 (file)
@@ -291,6 +291,8 @@ void http_client_request_destroy(struct http_client_request **_req)
 
        if (req->queue != NULL)
                http_client_queue_drop_request(req->queue, req);
+       if (req->delayed_error != NULL)
+               http_client_remove_request_error(req->client, req);
 
        if (req->destroy_callback != NULL) {
                void (*callback)(void *) = req->destroy_callback;
@@ -1280,7 +1282,8 @@ void http_client_request_abort(struct http_client_request **_req)
 
        *_req = NULL;
 
-       if (req->state >= HTTP_REQUEST_STATE_FINISHED)
+       if (req->state >= HTTP_REQUEST_STATE_FINISHED &&
+               req->delayed_error_status == 0)
                return;
 
        req->callback = NULL;
index b1651244925daa2d0295878abeeb70e872674f88..245192fdaca7130194829579c83d6997a0bbc58c 100644 (file)
@@ -151,6 +151,84 @@ static void test_unconfigured_ssl(void)
        test_end();
 }
 
+/*
+ * Unconfigured SSL abort
+ */
+
+/* client */
+
+struct _unconfigured_ssl_abort {
+       unsigned int count;
+};
+
+static void
+test_client_unconfigured_ssl_abort_response1(
+       const struct http_response *resp,
+       struct _unconfigured_ssl_abort *ctx ATTR_UNUSED)
+{
+       if (debug)
+               i_debug("RESPONSE: %u %s", resp->status, resp->reason);
+
+       test_out_quiet("inappropriate callback", FALSE);
+}
+
+static void
+test_client_unconfigured_ssl_abort_response2(
+       const struct http_response *resp,
+       struct _unconfigured_ssl_abort *ctx)
+{
+       if (debug)
+               i_debug("RESPONSE: %u %s", resp->status, resp->reason);
+
+       test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_CONNECT_FAILED);
+       test_assert(resp->reason != NULL && *resp->reason != '\0');
+
+       i_free(ctx);
+       io_loop_stop(ioloop);
+}
+
+static bool
+test_client_unconfigured_ssl_abort(const struct http_client_settings *client_set)
+{
+       struct http_client_request *hreq;
+       struct _unconfigured_ssl_abort *ctx;
+
+       ctx = i_new(struct _unconfigured_ssl_abort, 1);
+       ctx->count = 1;
+
+       http_client = http_client_init(client_set);
+
+       hreq = http_client_request(http_client,
+               "GET", "127.0.0.1", "/unconfigured-ssl.txt",
+               test_client_unconfigured_ssl_abort_response1, ctx);
+       http_client_request_set_ssl(hreq, TRUE);
+       http_client_request_submit(hreq);
+       http_client_request_abort(&hreq);
+
+       hreq = http_client_request(http_client,
+               "GET", "127.0.0.1", "/unconfigured-ssl2.txt",
+               test_client_unconfigured_ssl_abort_response2, ctx);
+       http_client_request_set_ssl(hreq, TRUE);
+       http_client_request_submit(hreq);
+
+       return TRUE;
+}
+
+/* test */
+
+static void test_unconfigured_ssl_abort(void)
+{
+       struct http_client_settings http_client_set;
+
+       test_client_defaults(&http_client_set);
+
+       test_begin("unconfigured ssl abort");
+       test_run_client_server(&http_client_set,
+               test_client_unconfigured_ssl_abort,
+               NULL, 0, NULL);
+       test_end();
+}
+
 /*
  * Invalid URL
  */
@@ -2745,6 +2823,7 @@ static void test_reconnect_failure(void)
 
 static void (*const test_functions[])(void) = {
        test_unconfigured_ssl,
+       test_unconfigured_ssl_abort,
        test_invalid_url,
        test_host_lookup_failed,
        test_connection_refused,