From: Timo Sirainen Date: Mon, 27 May 2019 14:55:56 +0000 (+0300) Subject: lib-http: Add http_client_request_lookup_header() X-Git-Tag: 2.2.36.4~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=088cb18e010fd8cf6d7ba9ad1ca283d0d2170442;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Add http_client_request_lookup_header() --- diff --git a/src/lib-http/http-client-request.c b/src/lib-http/http-client-request.c index 7f98bec58f..3b2a5c0e57 100644 --- a/src/lib-http/http-client-request.c +++ b/src/lib-http/http-client-request.c @@ -440,6 +440,20 @@ void http_client_request_remove_header(struct http_client_request *req, str_delete(req->headers, key_pos, next_pos - key_pos); } +const char *http_client_request_lookup_header(struct http_client_request *req, + const char *key) +{ + size_t key_pos, value_pos, next_pos; + + if (!http_client_request_lookup_header_pos(req, key, &key_pos, + &value_pos, &next_pos)) + return NULL; + + /* don't return CRLF */ + return t_strndup(str_data(req->headers) + value_pos, + next_pos - value_pos - 2); +} + void http_client_request_set_date(struct http_client_request *req, time_t date) { diff --git a/src/lib-http/http-client.h b/src/lib-http/http-client.h index 74733502a7..0bd71d8b39 100644 --- a/src/lib-http/http-client.h +++ b/src/lib-http/http-client.h @@ -288,6 +288,9 @@ void http_client_request_add_header(struct http_client_request *req, headers. */ void http_client_request_remove_header(struct http_client_request *req, const char *key); +/* lookup the value for a header added earlier. Returns NULL if not found. */ +const char *http_client_request_lookup_header(struct http_client_request *req, + const char *key); /* set the value of the "Date" header for the request using a time_t value. Use this instead of setting it directly using