From: Timo Sirainen Date: Tue, 8 Oct 2013 07:04:55 +0000 (+0300) Subject: lib-http: Added setting for User-Agent header. X-Git-Tag: 2.2.7~92 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b99130e4cf4af4e6b103b949456222f3a2dff424;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Added setting for User-Agent header. --- diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 93f9346d51..378efce670 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -74,6 +74,7 @@ struct http_client_request { 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 --git a/src/lib-http/http-client-request.c b/src/lib-http/http-client-request.c index 9d0eb141da..448ff429b6 100644 --- a/src/lib-http/http-client-request.c +++ b/src/lib-http/http-client-request.c @@ -175,6 +175,10 @@ void http_client_request_add_header(struct http_client_request *req, 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 @@ static int http_client_request_send_real(struct http_client_request *req, 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 --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index b598d5cd55..5e8aa919ed 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -75,12 +75,10 @@ struct http_client *http_client_init(const struct http_client_settings *set) 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 --git a/src/lib-http/http-client.h b/src/lib-http/http-client.h index 63327b6a8f..594da6ae56 100644 --- a/src/lib-http/http-client.h +++ b/src/lib-http/http-client.h @@ -41,6 +41,9 @@ struct http_client_settings { /* 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;