soup-http-input-stream: read data from leftover buffers in finished messages
authorSergio Villar Senin <svillar@igalia.com>
Fri, 16 Sep 2011 15:08:08 +0000 (17:08 +0200)
committerSergio Villar Senin <svillar@igalia.com>
Fri, 16 Sep 2011 17:01:25 +0000 (19:01 +0200)
soup_http_input_stream_read(_async) allow clients to read pending data in
leftover buffers even if the SoupMessage used by the stream is finished.

https://bugzilla.gnome.org/show_bug.cgi?id=659256

libsoup/soup-http-input-stream.c

index 82e7d46..6aa153d 100644 (file)
@@ -489,13 +489,13 @@ soup_http_input_stream_read (GInputStream  *stream,
 {
        SoupHTTPInputStreamPrivate *priv = SOUP_HTTP_INPUT_STREAM_GET_PRIVATE (stream);
 
-       if (priv->finished)
-               return 0;
-
        /* If there is data leftover from a previous read, return it. */
        if (priv->leftover_bufsize)
                return read_from_leftover (priv, buffer, count);
 
+       if (priv->finished)
+               return 0;
+
        /* No leftover data, accept one chunk from the network */
        soup_http_input_stream_prepare_for_io (stream, cancellable, buffer, count);
        while (!priv->finished && priv->caller_nread == 0 &&
@@ -701,16 +701,16 @@ soup_http_input_stream_read_async (GInputStream        *stream,
                                            callback, user_data,
                                            soup_http_input_stream_read_async);
 
-       if (priv->finished) {
-               g_simple_async_result_set_op_res_gssize (result, 0);
+       if (priv->leftover_bufsize) {
+               gsize nread = read_from_leftover (priv, buffer, count);
+               g_simple_async_result_set_op_res_gssize (result, nread);
                g_simple_async_result_complete_in_idle (result);
                g_object_unref (result);
                return;
        }
 
-       if (priv->leftover_bufsize) {
-               gsize nread = read_from_leftover (priv, buffer, count);
-               g_simple_async_result_set_op_res_gssize (result, nread);
+       if (priv->finished) {
+               g_simple_async_result_set_op_res_gssize (result, 0);
                g_simple_async_result_complete_in_idle (result);
                g_object_unref (result);
                return;