]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Add http_client_request_lookup_header()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 27 May 2019 14:55:56 +0000 (17:55 +0300)
committerMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Tue, 11 Jun 2019 10:49:22 +0000 (13:49 +0300)
src/lib-http/http-client-request.c
src/lib-http/http-client.h

index 7f98bec58fcc2c4c6e9fb3ceeae40916dfc42bc4..3b2a5c0e57d31eb09dd7340cf546d60c80dc686f 100644 (file)
@@ -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)
 {
index 74733502a7e780fe19d80a312396862513f68ea6..0bd71d8b390c7d8e91711fa9a63cd931ccb09109 100644 (file)
@@ -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