]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Added ability to configure a specific proxy for individual requests.
authorStephan Bosch <stephan@rename-it.nl>
Wed, 27 Apr 2016 10:00:25 +0000 (12:00 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 9 Nov 2016 12:23:17 +0000 (14:23 +0200)
This way, a request can be routed to a specific proxy (or origin server). The destination can also be a unix socket.

src/lib-http/http-client-request.c
src/lib-http/http-client.h

index 82702e5b3ca89259f3c41cbdbd5db9fd8b7717eb..813cb1218b5edc73eedca261f2d33ca83ecb1426 100644 (file)
@@ -454,6 +454,26 @@ void http_client_request_set_auth_simple(struct http_client_request *req,
        req->password = p_strdup(req->pool, password);
 }
 
+void http_client_request_set_proxy_url(struct http_client_request *req,
+       const struct http_url *proxy_url)
+{
+       i_assert(req->state == HTTP_REQUEST_STATE_NEW ||
+               req->state == HTTP_REQUEST_STATE_GOT_RESPONSE);
+
+       req->host_url = http_url_clone_authority(req->pool, proxy_url);
+       req->host_socket = NULL;
+}
+
+void http_client_request_set_proxy_socket(struct http_client_request *req,
+       const char *proxy_socket)
+{
+       i_assert(req->state == HTTP_REQUEST_STATE_NEW ||
+               req->state == HTTP_REQUEST_STATE_GOT_RESPONSE);
+
+       req->host_socket = p_strdup(req->pool, proxy_socket);
+       req->host_url = NULL;
+}
+
 void http_client_request_delay_until(struct http_client_request *req,
        time_t time)
 {
@@ -542,7 +562,8 @@ static void http_client_request_do_submit(struct http_client_request *req)
        struct http_client_host *host;
        const char *proxy_socket_path = client->set.proxy_socket_path;
        const struct http_url *proxy_url = client->set.proxy_url;
-       bool have_proxy = (proxy_socket_path != NULL) || (proxy_url != NULL);
+       bool have_proxy = (proxy_socket_path != NULL) || (proxy_url != NULL) ||
+               (req->host_socket != NULL) || (req->host_url != NULL);
        const char *authority, *target;
 
        i_assert(req->state == HTTP_REQUEST_STATE_NEW);
@@ -559,8 +580,12 @@ static void http_client_request_do_submit(struct http_client_request *req)
 
        /* determine what host to contact to submit this request */
        if (have_proxy) {
-               if (req->origin_url.have_ssl && !client->set.no_ssl_tunnel &&
-                       !req->connect_tunnel) {
+               if (req->host_socket != NULL) {               /* specific socket proxy */
+                       req->host_url = NULL;
+               } else if (req->host_url != NULL) {           /* specific normal proxy */
+                       req->host_socket = NULL;
+               } else if (req->origin_url.have_ssl &&
+                       !client->set.no_ssl_tunnel &&   !req->connect_tunnel) {
                        req->host_url = &req->origin_url;           /* tunnel to origin server */
                        req->ssl_tunnel = TRUE;
                } else if (proxy_socket_path != NULL) {
index 493bf19f94bf6fb2a9b7187bb66e5c7a65862153..6fdc21462703671024f5f9d5014182fa2ce2a1be 100644 (file)
@@ -303,6 +303,15 @@ void http_client_request_set_max_attempts(struct http_client_request *req,
 void http_client_request_set_auth_simple(struct http_client_request *req,
        const char *username, const char *password);
 
+/* Assign a proxy to use for this particular request. This overrides any
+   proxy defined in the client settings. */
+void http_client_request_set_proxy_url(struct http_client_request *req,
+       const struct http_url *proxy_url);
+/* Like http_client_request_set_proxy_url(), but the proxy is behind a unix
+   socket. */
+void http_client_request_set_proxy_socket(struct http_client_request *req,
+       const char *proxy_socket);
+
 /* delay handling of this request to a later time. This way, a request can be
    submitted that is held for some time until a certain time period has passed.
  */