dovecot-2.2: lib-http: Added setting for User-Agent header.

dovecot at dovecot.org dovecot at dovecot.org
Tue Oct 8 10:05:01 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/fe009d4ba4ed
changeset: 16837:fe009d4ba4ed
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Oct 08 10:04:55 2013 +0300
description:
lib-http: Added setting for User-Agent header.

diffstat:

 src/lib-http/http-client-private.h |   1 +
 src/lib-http/http-client-request.c |   8 ++++++++
 src/lib-http/http-client.c         |  10 ++++------
 src/lib-http/http-client.h         |   3 +++
 4 files changed, 16 insertions(+), 6 deletions(-)

diffs (69 lines):

diff -r 4e44453887b6 -r fe009d4ba4ed src/lib-http/http-client-private.h
--- a/src/lib-http/http-client-private.h	Sun Oct 06 13:21:15 2013 +0300
+++ b/src/lib-http/http-client-private.h	Tue Oct 08 10:04:55 2013 +0300
@@ -74,6 +74,7 @@
 	unsigned int have_hdr_expect:1;
 	unsigned int	have_hdr_host:1;
 	unsigned int have_hdr_body_spec:1;
+	unsigned int have_hdr_user_agent:1;
 
 	unsigned int payload_sync:1;
 	unsigned int payload_chunked:1;
diff -r 4e44453887b6 -r fe009d4ba4ed src/lib-http/http-client-request.c
--- a/src/lib-http/http-client-request.c	Sun Oct 06 13:21:15 2013 +0300
+++ b/src/lib-http/http-client-request.c	Tue Oct 08 10:04:55 2013 +0300
@@ -175,6 +175,10 @@
 		if (strcasecmp(key, "Transfer-Encoding") == 0)
 			req->have_hdr_body_spec = TRUE;
 		break;
+	case 'u': case 'U':
+		if (strcasecmp(key, "User-Agent") == 0)
+			req->have_hdr_user_agent = TRUE;
+		break;
 	}
 	str_printfa(req->headers, "%s: %s\r\n", key, value);
 }
@@ -450,6 +454,10 @@
 		str_append(rtext, http_date_create(req->date));
 		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);
+	}
 	if (!req->have_hdr_expect && req->payload_sync) {
 		str_append(rtext, "Expect: 100-continue\r\n");
 	}
diff -r 4e44453887b6 -r fe009d4ba4ed src/lib-http/http-client.c
--- a/src/lib-http/http-client.c	Sun Oct 06 13:21:15 2013 +0300
+++ b/src/lib-http/http-client.c	Tue Oct 08 10:04:55 2013 +0300
@@ -75,12 +75,10 @@
 	pool = pool_alloconly_create("http client", 1024);
 	client = p_new(pool, struct http_client, 1);
 	client->pool = pool;
-	if (set->dns_client_socket_path != NULL && *set->dns_client_socket_path != '\0') {
-		client->set.dns_client_socket_path =
-			p_strdup(pool, set->dns_client_socket_path);
-	}
-	if (set->rawlog_dir != NULL && *set->rawlog_dir != '\0')
-		client->set.rawlog_dir = p_strdup(pool, set->rawlog_dir);
+	client->set.dns_client_socket_path =
+		p_strdup_empty(pool, set->dns_client_socket_path);
+	client->set.user_agent = p_strdup_empty(pool, set->user_agent);
+	client->set.rawlog_dir = p_strdup_empty(pool, set->rawlog_dir);
 	client->set.ssl_ca_dir = p_strdup(pool, set->ssl_ca_dir);
 	client->set.ssl_ca_file = p_strdup(pool, set->ssl_ca_file);
 	client->set.ssl_ca = p_strdup(pool, set->ssl_ca);
diff -r 4e44453887b6 -r fe009d4ba4ed src/lib-http/http-client.h
--- a/src/lib-http/http-client.h	Sun Oct 06 13:21:15 2013 +0300
+++ b/src/lib-http/http-client.h	Tue Oct 08 10:04:55 2013 +0300
@@ -41,6 +41,9 @@
 	/* user cert */
 	const char *ssl_cert, *ssl_key, *ssl_key_password;
 
+	/* User-Agent: header (default: none) */
+	const char *user_agent;
+
 	const char *rawlog_dir;
 
 	unsigned int max_idle_time_msecs;


More information about the dovecot-cvs mailing list