dovecot-2.2: lib-http client: Implemented proxy authentication u...

dovecot at dovecot.org dovecot at dovecot.org
Tue Aug 18 18:02:36 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/cdf9e584c1c7
changeset: 18962:cdf9e584c1c7
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Tue Aug 18 20:39:24 2015 +0300
description:
lib-http client: Implemented proxy authentication using Basic scheme.

diffstat:

 src/lib-http/http-client-request.c |  15 +++++++++++++++
 src/lib-http/http-client.c         |  11 +++++++++--
 src/lib-http/http-client.h         |   2 +-
 3 files changed, 25 insertions(+), 3 deletions(-)

diffs (72 lines):

diff -r 5c53d13a30ab -r cdf9e584c1c7 src/lib-http/http-client-request.c
--- 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);
diff -r 5c53d13a30ab -r cdf9e584c1c7 src/lib-http/http-client.c
--- 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 =
diff -r 5c53d13a30ab -r cdf9e584c1c7 src/lib-http/http-client.h
--- 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;


More information about the dovecot-cvs mailing list