From f9181c7ad0b65b5798cf11dca2f1479e79661731 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sat, 23 Jan 2010 10:40:22 -0500 Subject: [PATCH] [SoupCodingGzip] discard trailing junk after decoding, for compatibility https://bugzilla.gnome.org/show_bug.cgi?id=606352 --- libsoup/soup-coding-gzip.c | 6 ++++++ tests/coding-test.c | 47 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/libsoup/soup-coding-gzip.c b/libsoup/soup-coding-gzip.c index b1731d5..60d57e2 100644 --- a/libsoup/soup-coding-gzip.c +++ b/libsoup/soup-coding-gzip.c @@ -129,6 +129,12 @@ apply_into (SoupCoding *coding, return SOUP_CODING_STATUS_ERROR; case Z_STREAM_END: + /* Discard any trailing junk, for compatibility with + * other browsers. FIXME: this really belongs in + * soup-message-io, but it's not possible to do there + * with the current API. + */ + *input_used = input_length; return SOUP_CODING_STATUS_COMPLETE; case Z_OK: diff --git a/tests/coding-test.c b/tests/coding-test.c index 47efb4a..e0dae15 100644 --- a/tests/coding-test.c +++ b/tests/coding-test.c @@ -26,7 +26,7 @@ server_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, SoupClientContext *context, gpointer data) { - const char *accept_encoding; + const char *accept_encoding, *junk; GSList *codings; char *file = NULL, *contents; gsize length; @@ -64,13 +64,20 @@ server_callback (SoupServer *server, SoupMessage *msg, soup_message_set_status (msg, SOUP_STATUS_OK); soup_message_body_append (msg->response_body, SOUP_MEMORY_TAKE, contents, length); + + junk = soup_message_headers_get_one (msg->request_headers, + "X-Trailing-Junk"); + if (junk) { + soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY, + junk, strlen (junk)); + } } static void do_coding_test (void) { SoupSession *session; - SoupMessage *msg, *msgz; + SoupMessage *msg, *msgz, *msgj; SoupURI *uri; const char *coding; @@ -124,12 +131,46 @@ do_coding_test (void) } else if (memcmp (msg->response_body->data, msgz->response_body->data, msg->response_body->length) != 0) { - debug_printf (1, " Message data mismatch\n"); + debug_printf (1, " Message data mismatch (plain/compressed)\n"); + errors++; + } + + debug_printf (1, "GET /mbox, Accept-Encoding: gzip, plus trailing junk\n"); + msgj = soup_message_new_from_uri ("GET", uri); + soup_message_headers_append (msgj->request_headers, + "X-Trailing-Junk", "junk!"); + soup_session_send_message (session, msgj); + if (!SOUP_STATUS_IS_SUCCESSFUL (msgj->status_code)) { + debug_printf (1, " Unexpected status %d %s\n", + msgj->status_code, msgj->reason_phrase); + errors++; + } + coding = soup_message_headers_get_one (msgj->response_headers, "Content-Encoding"); + if (!coding || g_ascii_strcasecmp (coding, "gzip") != 0) { + debug_printf (1, " Unexpected Content-Encoding: %s\n", + coding ? coding : "(none)"); + errors++; + } + if (!(soup_message_get_flags (msgj) & SOUP_MESSAGE_CONTENT_DECODED)) { + debug_printf (1, " SOUP_MESSAGE_CONTENT_DECODED not set!\n"); + errors++; + } + + if (msg->response_body->length != msgj->response_body->length) { + debug_printf (1, " Message length mismatch: %lu (plain) vs %lu (compressed w/ junk)\n", + (gulong)msg->response_body->length, + (gulong)msgj->response_body->length); + errors++; + } else if (memcmp (msg->response_body->data, + msgj->response_body->data, + msg->response_body->length) != 0) { + debug_printf (1, " Message data mismatch (plain/compressed w/ junk)\n"); errors++; } g_object_unref (msg); g_object_unref (msgz); + g_object_unref (msgj); soup_uri_free (uri); soup_test_session_abort_unref (session); -- 2.7.4