dovecot-2.2: lib-http: Added http_client_request_remove_header()

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 15 00:29:29 EET 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/3f3c9f93a0b3
changeset: 17103:3f3c9f93a0b3
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 15 00:28:35 2014 +0200
description:
lib-http: Added http_client_request_remove_header()

diffstat:

 src/lib-http/http-client-request.c |  28 ++++++++++++++++++++++++++++
 src/lib-http/http-client.h         |   2 ++
 2 files changed, 30 insertions(+), 0 deletions(-)

diffs (50 lines):

diff -r 63244d272133 -r 3f3c9f93a0b3 src/lib-http/http-client-request.c
--- a/src/lib-http/http-client-request.c	Wed Jan 15 00:28:20 2014 +0200
+++ b/src/lib-http/http-client-request.c	Wed Jan 15 00:28:35 2014 +0200
@@ -240,6 +240,34 @@
 	str_printfa(req->headers, "%s: %s\r\n", key, value);
 }
 
+void http_client_request_remove_header(struct http_client_request *req,
+				       const char *key)
+{
+	const unsigned char *data, *p;
+	size_t size, line_len, line_start_pos;
+	unsigned int key_len = strlen(key);
+
+	i_assert(req->state == HTTP_REQUEST_STATE_NEW ||
+		 /* allow calling for retries */
+		 req->state == HTTP_REQUEST_STATE_GOT_RESPONSE ||
+		 req->state == HTTP_REQUEST_STATE_ABORTED);
+
+	data = str_data(req->headers);
+	size = str_len(req->headers);
+	while ((p = memchr(data, '\n', size)) != NULL) {
+		line_len = (p+1) - data;
+		if (size > key_len && i_memcasecmp(data, key, key_len) == 0 &&
+		    data[key_len] == ':' && data[key_len+1] == ' ') {
+			/* key was found from header, replace its value */
+			line_start_pos = str_len(req->headers) - size;
+			str_delete(req->headers, line_start_pos, line_len);
+			break;
+		}
+		size -= line_len;
+		data += line_len;
+	}
+}
+
 void http_client_request_set_date(struct http_client_request *req,
 				    time_t date)
 {
diff -r 63244d272133 -r 3f3c9f93a0b3 src/lib-http/http-client.h
--- a/src/lib-http/http-client.h	Wed Jan 15 00:28:20 2014 +0200
+++ b/src/lib-http/http-client.h	Wed Jan 15 00:28:35 2014 +0200
@@ -172,6 +172,8 @@
 
 void http_client_request_add_header(struct http_client_request *req,
 				    const char *key, const char *value);
+void http_client_request_remove_header(struct http_client_request *req,
+				       const char *key);
 void http_client_request_set_date(struct http_client_request *req,
 				    time_t date);
 


More information about the dovecot-cvs mailing list