From f685b51fd3d8967af6958259eb16ac09b9aff820 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 14 Mar 2008 23:09:43 +0000 Subject: [PATCH] add an orig_http_version field. * libsoup/soup-message-private.h (SoupMessagePrivate): add an orig_http_version field. * libsoup/soup-message.c (soup_message_init): initialize orig_http_version. (soup_message_set_http_version): If called before the status code is received, set orig_http_version too. (soup_message_cleanup_response): Restore orig_http_version, so that we don't send an HTTP/1.0 request in response to an HTTP/1.0 redirect. #521848, Tommi Komulainen. * libsoup/soup-message-server-io.c (get_response_headers): actually output "HTTP/1.0", not "HTTP/1.1", if the message's http version is 1.0. * tests/redirect-test.c (server_callback): Add a regression test; set http_version to 1.0 when returning a redirect, but require it to be 1.1 when processing the following request svn path=/trunk/; revision=1108 --- ChangeLog | 21 +++++++++++++++++++++ libsoup/soup-message-private.h | 2 +- libsoup/soup-message-server-io.c | 3 ++- libsoup/soup-message.c | 14 ++++++++++++-- tests/redirect-test.c | 11 +++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 049d03d..d5579a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2008-03-14 Dan Winship + + * libsoup/soup-message-private.h (SoupMessagePrivate): add + an orig_http_version field. + + * libsoup/soup-message.c (soup_message_init): initialize + orig_http_version. + (soup_message_set_http_version): If called before the status code + is received, set orig_http_version too. + (soup_message_cleanup_response): Restore orig_http_version, so + that we don't send an HTTP/1.0 request in response to an HTTP/1.0 + redirect. #521848, Tommi Komulainen. + + * libsoup/soup-message-server-io.c (get_response_headers): + actually output "HTTP/1.0", not "HTTP/1.1", if the message's http + version is 1.0. + + * tests/redirect-test.c (server_callback): Add a regression test; + set http_version to 1.0 when returning a redirect, but require it + to be 1.1 when processing the following request + 2008-03-13 Xan Lopez * libsoup/soup-address.c: diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h index fd67a3d..c274ca4 100644 --- a/libsoup/soup-message-private.h +++ b/libsoup/soup-message-private.h @@ -28,7 +28,7 @@ typedef struct { guint msg_flags; - SoupHTTPVersion http_version; + SoupHTTPVersion http_version, orig_http_version; SoupURI *uri; diff --git a/libsoup/soup-message-server-io.c b/libsoup/soup-message-server-io.c index 3cf5870..bb02f01 100644 --- a/libsoup/soup-message-server-io.c +++ b/libsoup/soup-message-server-io.c @@ -100,7 +100,8 @@ get_response_headers (SoupMessage *msg, GString *headers, SoupMessageHeadersIter iter; const char *name, *value; - g_string_append_printf (headers, "HTTP/1.1 %d %s\r\n", + g_string_append_printf (headers, "HTTP/1.%c %d %s\r\n", + soup_message_get_http_version (msg) == SOUP_HTTP_1_0 ? '0' : '1', msg->status_code, msg->reason_phrase); claimed_encoding = soup_message_headers_get_encoding (msg->response_headers); diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c index 081b898..8c0676a 100644 --- a/libsoup/soup-message.c +++ b/libsoup/soup-message.c @@ -118,7 +118,7 @@ soup_message_init (SoupMessage *msg) SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg); priv->io_status = SOUP_MESSAGE_IO_STATUS_IDLE; - priv->http_version = SOUP_HTTP_1_1; + priv->http_version = priv->orig_http_version = SOUP_HTTP_1_1; msg->request_body = soup_message_body_new (); msg->request_headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_REQUEST); @@ -1032,6 +1032,8 @@ soup_message_get_proxy_auth (SoupMessage *msg) void soup_message_cleanup_response (SoupMessage *req) { + SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (req); + soup_message_body_truncate (req->response_body); soup_message_headers_clear (req->response_headers); @@ -1040,8 +1042,11 @@ soup_message_cleanup_response (SoupMessage *req) g_free ((char *) req->reason_phrase); req->reason_phrase = NULL; } + priv->http_version = priv->orig_http_version; + g_object_notify (G_OBJECT (req), SOUP_MESSAGE_STATUS_CODE); g_object_notify (G_OBJECT (req), SOUP_MESSAGE_REASON_PHRASE); + g_object_notify (G_OBJECT (req), SOUP_MESSAGE_HTTP_VERSION); } /** @@ -1110,9 +1115,14 @@ soup_message_get_flags (SoupMessage *msg) void soup_message_set_http_version (SoupMessage *msg, SoupHTTPVersion version) { + SoupMessagePrivate *priv; + g_return_if_fail (SOUP_IS_MESSAGE (msg)); + priv = SOUP_MESSAGE_GET_PRIVATE (msg); - SOUP_MESSAGE_GET_PRIVATE (msg)->http_version = version; + priv->http_version = version; + if (msg->status_code == SOUP_STATUS_NONE) + priv->orig_http_version = version; g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_HTTP_VERSION); } diff --git a/tests/redirect-test.c b/tests/redirect-test.c index 3f02224..d61a3ba 100644 --- a/tests/redirect-test.c +++ b/tests/redirect-test.c @@ -199,6 +199,14 @@ server_callback (SoupServer *server, SoupMessage *msg, return; } + /* Make sure that a HTTP/1.0 redirect doesn't cause an + * HTTP/1.0 re-request. (#521848) + */ + if (soup_message_get_http_version (msg) == SOUP_HTTP_1_0) { + soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); + return; + } + soup_message_set_status (msg, SOUP_STATUS_OK); soup_message_set_response (msg, "text/plain", SOUP_MEMORY_STATIC, @@ -213,6 +221,9 @@ server_callback (SoupServer *server, SoupMessage *msg, return; } + /* See above comment re bug 521848. */ + soup_message_set_http_version (msg, SOUP_HTTP_1_0); + soup_message_set_status (msg, status_code); if (*remainder) { soup_message_headers_replace (msg->response_headers, -- 2.7.4