Mercurial > dovecot > core-2.2
changeset 23014:c6116e84af30
lib-http: Add http_client_request_add_missing_header()
author | Timo Sirainen <timo.sirainen@open-xchange.com> |
---|---|
date | Mon, 27 May 2019 18:25:38 +0300 |
parents | ddfa057027c5 |
children | ae4659f289a9 |
files | src/lib-http/http-client-request.c src/lib-http/http-client.h |
diffstat | 2 files changed, 20 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/http-client-request.c Mon May 27 17:55:56 2019 +0300 +++ b/src/lib-http/http-client-request.c Mon May 27 18:25:38 2019 +0300 @@ -364,8 +364,10 @@ return FALSE; } -void http_client_request_add_header(struct http_client_request *req, - const char *key, const char *value) +static void +http_client_request_add_header_full(struct http_client_request *req, + const char *key, const char *value, + bool replace_existing) { size_t key_pos, value_pos, next_pos; @@ -418,13 +420,25 @@ if (!http_client_request_lookup_header_pos(req, key, &key_pos, &value_pos, &next_pos)) str_printfa(req->headers, "%s: %s\r\n", key, value); - else { + else if (replace_existing) { /* don't delete CRLF */ size_t old_value_len = next_pos - value_pos - 2; str_replace(req->headers, value_pos, old_value_len, value); } } +void http_client_request_add_header(struct http_client_request *req, + const char *key, const char *value) +{ + http_client_request_add_header_full(req, key, value, TRUE); +} + +void http_client_request_add_missing_header(struct http_client_request *req, + const char *key, const char *value) +{ + http_client_request_add_header_full(req, key, value, FALSE); +} + void http_client_request_remove_header(struct http_client_request *req, const char *key) {
--- a/src/lib-http/http-client.h Mon May 27 17:55:56 2019 +0300 +++ b/src/lib-http/http-client.h Mon May 27 18:25:38 2019 +0300 @@ -284,6 +284,9 @@ the value is replaced. */ void http_client_request_add_header(struct http_client_request *req, const char *key, const char *value); +/* add a custom header to the request. Do nothing if it was already added. */ +void http_client_request_add_missing_header(struct http_client_request *req, + const char *key, const char *value); /* remove a header added earlier. This has no influence on implicitly created headers. */ void http_client_request_remove_header(struct http_client_request *req,