]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Added setting for User-Agent header.
authorTimo Sirainen <tss@iki.fi>
Tue, 8 Oct 2013 07:04:55 +0000 (10:04 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 8 Oct 2013 07:04:55 +0000 (10:04 +0300)
src/lib-http/http-client-private.h
src/lib-http/http-client-request.c
src/lib-http/http-client.c
src/lib-http/http-client.h

index 93f9346d51dfc0f818dd3af0860c7c5a508c3551..378efce670fea5cae881310ae48a383a9b7001ef 100644 (file)
@@ -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;
index 9d0eb141da9e58ea2370613c6fcf17f22b015f10..448ff429b6bd4c67206ae79130608a8eb8cb00e4 100644 (file)
@@ -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");
        }
index b598d5cd554a3131cb668b45c1e9e76277e0a94e..5e8aa919eda932b75e66fc4ad0408a8cebe0a723 100644 (file)
@@ -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);
index 63327b6a8faa58683aa2628220daecd6fa63d7db..594da6ae56ef08cb6d5dc3533af5349b0e664271 100644 (file)
@@ -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;