summaryrefslogtreecommitdiff
path: root/libsoup/soup-filter-input-stream.c
diff options
context:
space:
mode:
authorDaniel Kolesa <dkolesa@igalia.com>2021-03-08 17:56:13 +0100
committerDaniel Kolesa <dkolesa@igalia.com>2021-03-08 18:46:26 +0100
commit12cfc749653ab2b869df2ec20c9b10e1264894e7 (patch)
tree0f4e68244899594dde3fc455dbfdda2ab97c4a74 /libsoup/soup-filter-input-stream.c
parent0335eb08db86ff2eb8983cabcb4ca697d4ff6c07 (diff)
downloadlibsoup-12cfc749653ab2b869df2ec20c9b10e1264894e7.tar.gz
Implement skip for SoupClientInputStream and SoupFilterInputStream
this enables calling `g_input_stream_skip` on response body input streams and getting predictable behavior (i.e. read but without explicit storage) the `skip` implementation for body input stream was insufficient, resulting in the stream state never incrementing properly
Diffstat (limited to 'libsoup/soup-filter-input-stream.c')
-rw-r--r--libsoup/soup-filter-input-stream.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libsoup/soup-filter-input-stream.c b/libsoup/soup-filter-input-stream.c
index fd4466f1..d3af6b72 100644
--- a/libsoup/soup-filter-input-stream.c
+++ b/libsoup/soup-filter-input-stream.c
@@ -57,7 +57,8 @@ read_from_buf (SoupFilterInputStream *fstream, gpointer buffer, gsize count)
if (buf->len < count)
count = buf->len;
- memcpy (buffer, buf->data, count);
+ if (buffer)
+ memcpy (buffer, buf->data, count);
if (count == buf->len) {
g_byte_array_free (buf, TRUE);
@@ -93,6 +94,26 @@ soup_filter_input_stream_read_fn (GInputStream *stream,
}
}
+static gssize
+soup_filter_input_stream_skip (GInputStream *stream,
+ gsize count,
+ GCancellable *cancellable,
+ GError **error)
+{
+ SoupFilterInputStream *fstream = SOUP_FILTER_INPUT_STREAM (stream);
+ SoupFilterInputStreamPrivate *priv = soup_filter_input_stream_get_instance_private (fstream);
+
+ if (!priv->in_read_until)
+ priv->need_more = FALSE;
+
+ if (priv->buf && !priv->in_read_until) {
+ return read_from_buf (fstream, NULL, count);
+ } else {
+ return g_input_stream_skip (G_FILTER_INPUT_STREAM (fstream)->base_stream,
+ count, cancellable, error);
+ }
+}
+
static gboolean
soup_filter_input_stream_is_readable (GPollableInputStream *stream)
{
@@ -156,6 +177,7 @@ soup_filter_input_stream_class_init (SoupFilterInputStreamClass *stream_class)
object_class->finalize = soup_filter_input_stream_finalize;
input_stream_class->read_fn = soup_filter_input_stream_read_fn;
+ input_stream_class->skip = soup_filter_input_stream_skip;
}
static void