Mercurial > dovecot > core-2.2
changeset 18962:cdf9e584c1c7
lib-http client: Implemented proxy authentication using Basic scheme.
author | Stephan Bosch <stephan@rename-it.nl> |
---|---|
date | Tue, 18 Aug 2015 20:39:24 +0300 |
parents | 5c53d13a30ab |
children | 07ceb84bf899 |
files | src/lib-http/http-client-request.c src/lib-http/http-client.c src/lib-http/http-client.h |
diffstat | 3 files changed, 25 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/http-client-request.c Tue Aug 18 20:39:24 2015 +0300 +++ b/src/lib-http/http-client-request.c Tue Aug 18 20:39:24 2015 +0300 @@ -254,6 +254,9 @@ if (strcasecmp(key, "Host") == 0) req->have_hdr_host = TRUE; break; + case 'p': case 'P': + i_assert(strcasecmp(key, "Proxy-Authorization") != 0); + break; case 't': case 'T': if (strcasecmp(key, "Transfer-Encoding") == 0) req->have_hdr_body_spec = TRUE; @@ -734,6 +737,7 @@ static int http_client_request_send_real(struct http_client_request *req, const char **error_r) { + 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); @@ -772,6 +776,17 @@ http_auth_create_credentials(rtext, &auth_creds); str_append(rtext, "\r\n"); } + if (http_client_request_to_proxy(req) && + set->proxy_username != NULL && set->proxy_password != NULL) { + struct http_auth_credentials auth_creds; + + http_auth_basic_credentials_init(&auth_creds, + set->proxy_username, set->proxy_password); + + str_append(rtext, "Proxy-Authorization: "); + http_auth_create_credentials(rtext, &auth_creds); + str_append(rtext, "\r\n"); + } if (!req->have_hdr_user_agent && req->client->set.user_agent != NULL) { str_printfa(rtext, "User-Agent: %s\r\n", req->client->set.user_agent);
--- a/src/lib-http/http-client.c Tue Aug 18 20:39:24 2015 +0300 +++ b/src/lib-http/http-client.c Tue Aug 18 20:39:24 2015 +0300 @@ -111,8 +111,15 @@ } else if (set->proxy_url != NULL) { client->set.proxy_url = http_url_clone(pool, set->proxy_url); } - client->set.proxy_username = p_strdup_empty(pool, set->proxy_username); - client->set.proxy_password = p_strdup_empty(pool, set->proxy_password); + if (set->proxy_username != NULL && *set->proxy_username != '\0') { + client->set.proxy_username = p_strdup_empty(pool, set->proxy_username); + client->set.proxy_password = p_strdup(pool, set->proxy_password); + } else if (set->proxy_url != NULL) { + client->set.proxy_username = + p_strdup_empty(pool, set->proxy_url->user); + client->set.proxy_password = + p_strdup(pool, set->proxy_url->password); + } client->set.max_idle_time_msecs = set->max_idle_time_msecs; client->set.max_parallel_connections =
--- a/src/lib-http/http-client.h Tue Aug 18 20:39:24 2015 +0300 +++ b/src/lib-http/http-client.h Tue Aug 18 20:39:24 2015 +0300 @@ -54,7 +54,7 @@ /* configuration for using a proxy */ const char *proxy_socket_path; /* FIXME: implement */ const struct http_url *proxy_url; - const char *proxy_username; /* FIXME: implement */ + const char *proxy_username; const char *proxy_password; const char *rawlog_dir;