[libsoup] Call soup_message_clean_response() when restarting a message



commit 6b2b958f588526fac12ccf8b73d14afd2195957f
Author: Dan Winship <danw gnome org>
Date:   Mon Aug 8 17:48:13 2011 -0400

    Call soup_message_clean_response() when restarting a message
    
    When a message got restarted, we were leaving the previous response
    state in the message, which is bad for various reasons.
    
    In particular, this caused a problem with non-keepalive redirections
    of https URLs through proxies (!), because after the second CONNECT
    succeeded, it would see that the message already had a status_code
    set, and so it thought the message had been cancelled or something
    while it was processing the CONNECT. proxy-test now has a regression
    test for this case.
    
    Based on patches and analysis from DongJae Kim and Thierry Reding.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=631368

 libsoup/soup-message-queue.c |    2 ++
 tests/httpd.conf.in          |    2 +-
 tests/proxy-test.c           |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/libsoup/soup-message-queue.c b/libsoup/soup-message-queue.c
index 88ce313..58fea58 100644
--- a/libsoup/soup-message-queue.c
+++ b/libsoup/soup-message-queue.c
@@ -79,6 +79,8 @@ queue_message_restarted (SoupMessage *msg, gpointer user_data)
 		item->conn = NULL;
 	}
 
+	soup_message_cleanup_response (msg);
+
 	g_cancellable_reset (item->cancellable);
 
 	item->state = SOUP_MESSAGE_STARTING;
diff --git a/tests/httpd.conf.in b/tests/httpd.conf.in
index 848031e..de0b75f 100644
--- a/tests/httpd.conf.in
+++ b/tests/httpd.conf.in
@@ -31,7 +31,7 @@ LoadModule ssl_module           @APACHE_SSL_MODULE_DIR@/mod_ssl.so
 DirectoryIndex index.txt
 TypesConfig /dev/null
 AddType application/x-httpd-php .php
-
+Redirect permanent /redirected /index.txt
 
 # Proxy #1: unauthenticated
 Listen 127.0.0.1:47526
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index 014da39..27d8d2e 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -200,6 +200,45 @@ do_proxy_fragment_test (SoupURI *base_uri)
 	soup_test_session_abort_unref (session);
 }
 
+static void
+do_proxy_redirect_test (void)
+{
+	SoupSession *session;
+	SoupURI *proxy_uri, *req_uri, *new_uri;
+	SoupMessage *msg;
+
+	debug_printf (1, "\nTesting redirection through proxy\n");
+
+	proxy_uri = soup_uri_new (proxies[SIMPLE_PROXY]);
+	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
+					 SOUP_SESSION_PROXY_URI, proxy_uri,
+					 NULL);
+	soup_uri_free (proxy_uri);
+
+	req_uri = soup_uri_new (HTTPS_SERVER);
+	soup_uri_set_path (req_uri, "/redirected");
+	msg = soup_message_new_from_uri (SOUP_METHOD_GET, req_uri);
+	soup_message_headers_append (msg->request_headers,
+				     "Connection", "close");
+	soup_session_send_message (session, msg);
+
+	new_uri = soup_message_get_uri (msg);
+	if (!strcmp (req_uri->path, new_uri->path)) {
+		debug_printf (1, "  message was not redirected!\n");
+		errors++;
+	}
+	soup_uri_free (req_uri);
+
+	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+		debug_printf (1, "  unexpected status %d %s!\n",
+			      msg->status_code, msg->reason_phrase);
+		errors++;
+	}
+
+	g_object_unref (msg);
+	soup_test_session_abort_unref (session);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -221,6 +260,7 @@ main (int argc, char **argv)
 	soup_uri_set_port (base_uri, soup_server_get_port (server));
 
 	do_proxy_fragment_test (base_uri);
+	do_proxy_redirect_test ();
 
 	soup_uri_free (base_uri);
 	soup_test_server_quit_unref (server);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]