dovecot-2.2: lib-http: Fixed redirect request target encoding an...

dovecot at dovecot.org dovecot at dovecot.org
Sun Aug 4 20:33:16 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/3af0ae411b37
changeset: 16643:3af0ae411b37
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Aug 04 20:33:05 2013 +0300
description:
lib-http: Fixed redirect request target encoding and NULL target.
Patch by Stephan Bosch.

diffstat:

 src/lib-http/http-client-request.c |  11 +++++----
 src/lib-http/http-url.c            |  42 +++++++++++++++++++++++++------------
 src/lib-http/http-url.h            |   2 +
 3 files changed, 36 insertions(+), 19 deletions(-)

diffs (120 lines):

diff -r 3c2e1879fdf6 -r 3af0ae411b37 src/lib-http/http-client-request.c
--- a/src/lib-http/http-client-request.c	Sun Aug 04 18:34:43 2013 +0300
+++ b/src/lib-http/http-client-request.c	Sun Aug 04 20:33:05 2013 +0300
@@ -68,7 +68,7 @@
 	req->method = p_strdup(pool, method);
 	req->hostname = p_strdup(pool, host);
 	req->port = HTTP_DEFAULT_PORT;
-	req->target = p_strdup(pool, target);
+	req->target = (target == NULL ? "/" : p_strdup(pool, target));
 	req->callback = callback;
 	req->context = context;
 	req->headers = str_new(default_pool, 256);
@@ -555,7 +555,7 @@
 	unsigned int status, const char *location)
 {
 	struct http_url *url;
-	const char *error;
+	const char *error, *target;
 	unsigned int newport;
 
 	/* parse URL */
@@ -607,16 +607,17 @@
 	}
 
 	newport = (url->have_port ? url->port : (url->have_ssl ? 443 : 80));
+	target = http_url_create_target(url);
 
-	http_client_request_debug(req, "Redirecting to http://%s:%u%s",
-		url->host_name, newport, url->path);
+	http_client_request_debug(req, "Redirecting to http%s://%s:%u%s",
+		(url->have_ssl ? "s" : ""), url->host_name, newport, target);
 
 	// FIXME: handle literal IP specially (avoid duplicate parsing)
 	req->host = NULL;
 	req->conn = NULL;
 	req->hostname = p_strdup(req->pool, url->host_name);
 	req->port = newport;
-	req->target = p_strdup(req->pool, url->path);
+	req->target = p_strdup(req->pool, target);
 	req->ssl = url->have_ssl;
 
 	/* https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-21
diff -r 3c2e1879fdf6 -r 3af0ae411b37 src/lib-http/http-url.c
--- a/src/lib-http/http-url.c	Sun Aug 04 18:34:43 2013 +0300
+++ b/src/lib-http/http-url.c	Sun Aug 04 20:33:05 2013 +0300
@@ -237,6 +237,24 @@
  * HTTP URL construction
  */
 
+static void http_url_add_target(string_t *urlstr, const struct http_url *url)
+{
+	if (url->path == NULL || *url->path == '\0') {
+		/* Older syntax of RFC 2616 requires this slash at all times for an
+			 absolute URL
+		 */
+		str_append_c(urlstr, '/');
+	} else {
+		uri_append_path_data(urlstr, "", url->path);
+	}
+
+	/* query (pre-encoded) */
+	if (url->enc_query != NULL) {
+		str_append_c(urlstr, '?');
+		str_append(urlstr, url->enc_query);
+	}
+}
+
 const char *http_url_create(const struct http_url *url)
 {
 	string_t *urlstr = t_str_new(512);
@@ -259,20 +277,7 @@
 	if (url->have_port)
 		uri_append_port(urlstr, url->port);
 
-	if (url->path == NULL || *url->path == '\0') {
-		/* Older syntax of RFC 2616 requires this slash at all times for an
-			 absolute URL
-		 */
-		str_append_c(urlstr, '/');
-	} else {
-		uri_append_path_data(urlstr, "", url->path);
-	}
-
-	/* query (pre-encoded) */
-	if (url->enc_query != NULL) {
-		str_append_c(urlstr, '?');
-		str_append(urlstr, url->enc_query);
-	}
+	http_url_add_target(urlstr, url);
 
 	/* fragment */
 	if (url->enc_fragment != NULL) {
@@ -283,6 +288,15 @@
 	return str_c(urlstr);
 }
 
+const char *http_url_create_target(const struct http_url *url)
+{
+	string_t *urlstr = t_str_new(256);
+
+	http_url_add_target(urlstr, url);
+
+	return str_c(urlstr);
+}
+
 void http_url_escape_param(string_t *out, const char *data)
 {
 	uri_append_query_data(out, "&;/?=+", data);
diff -r 3c2e1879fdf6 -r 3af0ae411b37 src/lib-http/http-url.h
--- a/src/lib-http/http-url.h	Sun Aug 04 18:34:43 2013 +0300
+++ b/src/lib-http/http-url.h	Sun Aug 04 20:33:05 2013 +0300
@@ -45,6 +45,8 @@
 
 const char *http_url_create(const struct http_url *url);
 
+const char *http_url_create_target(const struct http_url *url);
+
 void http_url_escape_param(string_t *out, const char *data);
 
 #endif


More information about the dovecot-cvs mailing list