[libsoup] SoupConverterWrapper: handle empty "compressed" responses



commit 97d2b4dc9cbf4f0098bd21e71beabfeba9f62f81
Author: Dan Winship <danw gnome org>
Date:   Tue Jul 17 17:00:07 2012 -0400

    SoupConverterWrapper: handle empty "compressed" responses
    
    If a server sends an empty response but includes a Content-Encoding
    header (in particular, in a HEAD or 304 response), suppress the
    PARTIAL_INPUT error from the GZlibDecompressor and just return 0.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679527 (?)

 libsoup/soup-converter-wrapper.c |    9 +++++++
 tests/coding-test.c              |   49 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-converter-wrapper.c b/libsoup/soup-converter-wrapper.c
index 45d34a3..8aa000b 100644
--- a/libsoup/soup-converter-wrapper.c
+++ b/libsoup/soup-converter-wrapper.c
@@ -270,6 +270,15 @@ soup_converter_wrapper_real_convert (GConverter *converter,
 		return result;
 	}
 
+	if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT) &&
+	    !priv->started && inbuf_size == 0 &&
+	    (flags & G_CONVERTER_INPUT_AT_END)) {
+		/* Server claimed compression but there was no message body. */
+		g_error_free (my_error);
+		*bytes_written = 0;
+		return G_CONVERTER_FINISHED;
+	}
+
 	if (!g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA) ||
 	    priv->started) {
 		g_propagate_error (error, my_error);
diff --git a/tests/coding-test.c b/tests/coding-test.c
index 8c68a35..cda4b89 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -106,8 +106,10 @@ server_callback (SoupServer *server, SoupMessage *msg,
 	soup_message_set_status (msg, SOUP_STATUS_OK);
 	soup_message_headers_set_encoding (msg->response_headers, SOUP_ENCODING_CHUNKED);
 
-	soup_message_body_append (msg->response_body,
-				  SOUP_MEMORY_TAKE, contents, length);
+	if (!soup_header_contains (options, "empty")) {
+		soup_message_body_append (msg->response_body,
+					  SOUP_MEMORY_TAKE, contents, length);
+	}
 
 	if (soup_header_contains (options, "trailing-junk")) {
 		soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY,
@@ -511,6 +513,48 @@ do_coding_req_test (void)
 	soup_test_session_abort_unref (session);
 }
 
+static void
+do_coding_empty_test (void)
+{
+	SoupSession *session;
+	SoupMessage *msg;
+	SoupURI *uri;
+	SoupRequester *requester;
+	SoupRequest *req;
+	GByteArray *body;
+
+	debug_printf (1, "\nEmpty allegedly-encoded body test\n");
+
+	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
+					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
+					 SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
+					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_REQUESTER,
+					 NULL);
+	requester = (SoupRequester *)soup_session_get_feature (session, SOUP_TYPE_REQUESTER);
+	uri = soup_uri_new_with_base (base_uri, "/mbox");
+
+	debug_printf (1, "  SoupMessage\n");
+	msg = soup_message_new_from_uri ("GET", uri);
+	soup_message_headers_append (msg->request_headers,
+				     "X-Test-Options", "empty");
+	soup_session_send_message (session, msg);
+	check_response (msg, "gzip", "text/plain", EXPECT_NOT_DECODED);
+	g_object_unref (msg);
+
+	debug_printf (1, "  SoupRequest\n");
+	req = soup_requester_request_uri (requester, uri, NULL);
+	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
+	soup_message_headers_append (msg->request_headers,
+				     "X-Test-Options", "empty");
+	g_object_unref (msg);
+	body = do_single_coding_req_test (req, "gzip", "text/plain", EXPECT_NOT_DECODED);
+	g_byte_array_free (body, TRUE);
+	g_object_unref (req);
+
+	soup_test_session_abort_unref (session);
+}
+
+
 int
 main (int argc, char **argv)
 {
@@ -523,6 +567,7 @@ main (int argc, char **argv)
 
 	do_coding_test ();
 	do_coding_req_test ();
+	do_coding_empty_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]