changeset 23013:ddfa057027c5

lib-http: Add http_client_request_lookup_header()
author Timo Sirainen <timo.sirainen@open-xchange.com>
date Mon, 27 May 2019 17:55:56 +0300
parents c3a83810cf5b
children c6116e84af30
files src/lib-http/http-client-request.c src/lib-http/http-client.h
diffstat 2 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-http/http-client-request.c	Mon May 27 17:53:16 2019 +0300
+++ b/src/lib-http/http-client-request.c	Mon May 27 17:55:56 2019 +0300
@@ -440,6 +440,20 @@
 		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)
 {
--- a/src/lib-http/http-client.h	Mon May 27 17:53:16 2019 +0300
+++ b/src/lib-http/http-client.h	Mon May 27 17:55:56 2019 +0300
@@ -288,6 +288,9 @@
    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