Actually test chunked encoding, and fix some hangs
authorGustavo Noronha Silva <gustavo.noronha@collabora.co.uk>
Fri, 10 Jul 2009 13:29:28 +0000 (14:29 +0100)
committerGustavo Noronha Silva <gns@gnome.org>
Fri, 10 Jul 2009 14:47:11 +0000 (15:47 +0100)
The test was not really testing chunked encoding, because of incorrect
handling of the query string in the SoupURI, now it does. This has
exposed a couple hangs.

This change also avoids hanging on chunked encoding messages on the
sniffing test by calling soup_message_body_complete(), and by
sanitizing IO read state and read_length inconditionally when we reach
got_body, during message IO.

libsoup/soup-message-io.c
tests/sniffing-test.c

index 10657b7..5951e98 100644 (file)
@@ -866,6 +866,14 @@ io_read (SoupSocket *sock, SoupMessage *msg)
                        return;
 
        got_body:
+               /* If we end up returning, read_state needs to be set
+                * to IO_STATE_BODY, and read_length must be 0; since
+                * we may be coming from STATE_TRAILERS, or may be
+                * doing a read-to-eof, we sanitize these here.
+                */
+               io->read_state = SOUP_MESSAGE_IO_STATE_BODY;
+               io->read_length = 0;
+
                /* A chunk of data may have been read and the emission
                 * of got_chunk delayed because we wanted to wait for
                 * more chunks to arrive, for doing content sniffing,
@@ -885,16 +893,6 @@ io_read (SoupSocket *sock, SoupMessage *msg)
                                soup_buffer_free (sniffed_buffer);
                                soup_message_body_free (io->delayed_chunk_data);
                                io->delayed_chunk_data = NULL;
-
-                               /* If we end up returning, read_state
-                                * needs to be set to IO_STATE_BODY,
-                                * and read_length must be 0; since we
-                                * may be coming from STATE_TRAILERS,
-                                * or may be doing a read-to-eof, we
-                                * sanitize these here.
-                                */
-                               io->read_state = SOUP_MESSAGE_IO_STATE_BODY;
-                               io->read_length = 0;
                                SOUP_MESSAGE_IO_RETURN_IF_CANCELLED_OR_PAUSED;
                        }
                }
index ad2690f..6cf6a03 100644 (file)
@@ -24,6 +24,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
        char *chunked;
        char *contents;
        gsize length;
+       gboolean use_chunked_encoding = FALSE;
 
        if (msg->method != SOUP_METHOD_GET) {
                soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
@@ -34,9 +35,11 @@ server_callback (SoupServer *server, SoupMessage *msg,
 
        if (query) {
                chunked = g_hash_table_lookup (query, "chunked");
-               if (chunked && g_str_equal (chunked, "yes"))
+               if (chunked && g_str_equal (chunked, "yes")) {
                        soup_message_headers_set_encoding (msg->response_headers,
                                                           SOUP_ENCODING_CHUNKED);
+                       use_chunked_encoding = TRUE;
+               }
        }
 
        if (!strcmp (path, "/mbox")) {
@@ -160,6 +163,8 @@ server_callback (SoupServer *server, SoupMessage *msg,
                                             "Content-Type", "text/plain");
        }
 
+       if (use_chunked_encoding)
+               soup_message_body_complete (msg->response_body);
 }
 
 static gboolean
@@ -245,6 +250,8 @@ do_signals_test (gboolean should_content_sniff,
        if (chunked_encoding)
                soup_uri_set_query (uri, "chunked=yes");
 
+       soup_message_set_uri (msg, uri);
+
        soup_message_body_set_accumulate (msg->response_body, should_accumulate);
 
        g_object_connect (msg,