From: Gustavo Noronha Silva Date: Fri, 10 Jul 2009 13:29:28 +0000 (+0100) Subject: Actually test chunked encoding, and fix some hangs X-Git-Tag: LIBSOUP_2_27_4~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c0d924c6808b20540a76d0d2e9c266dc441b862;p=platform%2Fupstream%2Flibsoup.git Actually test chunked encoding, and fix some hangs 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. --- diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c index 10657b7..5951e98 100644 --- a/libsoup/soup-message-io.c +++ b/libsoup/soup-message-io.c @@ -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; } } diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c index ad2690f..6cf6a03 100644 --- a/tests/sniffing-test.c +++ b/tests/sniffing-test.c @@ -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,