[libsoup] message: add soup_message_try_sniff_content()
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] message: add soup_message_try_sniff_content()
- Date: Fri, 14 May 2021 09:04:24 +0000 (UTC)
commit 8a4e1e707d13b19c9b57f49c536d6ce201c72e8f
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Fri May 14 11:01:48 2021 +0200
message: add soup_message_try_sniff_content()
And remove soup_message_get_content_sniffer(). This moves code from
http1 io implementation to SoupMessage to be reused by http2 too.
libsoup/soup-client-message-io-http1.c | 15 ++-------------
libsoup/soup-message-private.h | 6 +++++-
libsoup/soup-message.c | 34 ++++++++++++++++++++++++++--------
3 files changed, 33 insertions(+), 22 deletions(-)
---
diff --git a/libsoup/soup-client-message-io-http1.c b/libsoup/soup-client-message-io-http1.c
index 12ee83ad..d0e87b32 100644
--- a/libsoup/soup-client-message-io-http1.c
+++ b/libsoup/soup-client-message-io-http1.c
@@ -22,7 +22,6 @@
#include "soup-client-input-stream.h"
#include "soup-connection.h"
#include "soup-session-private.h"
-#include "content-sniffer/soup-content-sniffer-stream.h"
#include "soup-filter-input-stream.h"
#include "soup-logger-private.h"
#include "soup-message-private.h"
@@ -605,18 +604,8 @@ io_read (SoupClientMessageIOHTTP1 *client_io,
g_object_unref (body_istream);
}
- if (soup_message_get_content_sniffer (msg)) {
- SoupContentSnifferStream *sniffer_stream = SOUP_CONTENT_SNIFFER_STREAM
(io->body_istream);
- const char *content_type;
- GHashTable *params;
-
- if (!soup_content_sniffer_stream_is_ready (sniffer_stream, blocking,
- cancellable, error))
- return FALSE;
-
- content_type = soup_content_sniffer_stream_sniff (sniffer_stream, ¶ms);
- soup_message_content_sniffed (msg, content_type, params);
- }
+ if (!soup_message_try_sniff_content (msg, io->body_istream, blocking, cancellable, error))
+ return FALSE;
io->read_state = SOUP_MESSAGE_IO_STATE_BODY;
break;
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 9eea56e4..ce7fcb46 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -101,9 +101,13 @@ void soup_message_set_connection (SoupMessage *msg,
SoupClientMessageIO *soup_message_get_io_data (SoupMessage *msg);
-SoupContentSniffer *soup_message_get_content_sniffer (SoupMessage *msg);
void soup_message_set_content_sniffer (SoupMessage *msg,
SoupContentSniffer *sniffer);
+gboolean soup_message_try_sniff_content (SoupMessage *msg,
+ GInputStream *stream,
+ gboolean blocking,
+ GCancellable *cancellable,
+ GError **error);
GInputStream *soup_message_get_request_body_stream (SoupMessage *msg);
void soup_message_set_reason_phrase (SoupMessage *msg,
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index f17bafb9..5f74516a 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -17,6 +17,7 @@
#include "soup-message-private.h"
#include "soup-message-metrics-private.h"
#include "soup-uri-utils-private.h"
+#include "content-sniffer/soup-content-sniffer-stream.h"
/**
* SECTION:soup-message
@@ -2310,14 +2311,6 @@ soup_message_io_get_response_istream (SoupMessage *msg,
return soup_client_message_io_get_response_stream (priv->io_data, msg, error);
}
-SoupContentSniffer *
-soup_message_get_content_sniffer (SoupMessage *msg)
-{
- SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
-
- return priv->sniffer;
-}
-
void
soup_message_set_content_sniffer (SoupMessage *msg, SoupContentSniffer *sniffer)
{
@@ -2329,6 +2322,31 @@ soup_message_set_content_sniffer (SoupMessage *msg, SoupContentSniffer *sniffer)
priv->sniffer = sniffer ? g_object_ref (sniffer) : NULL;
}
+gboolean
+soup_message_try_sniff_content (SoupMessage *msg,
+ GInputStream *stream,
+ gboolean blocking,
+ GCancellable *cancellable,
+ GError **error)
+{
+ SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
+ SoupContentSnifferStream *sniffer_stream;
+ const char *content_type;
+ GHashTable *params;
+
+ if (!priv->sniffer)
+ return TRUE;
+
+ sniffer_stream = SOUP_CONTENT_SNIFFER_STREAM (stream);
+ if (!soup_content_sniffer_stream_is_ready (sniffer_stream, blocking, cancellable, error))
+ return FALSE;
+
+ content_type = soup_content_sniffer_stream_sniff (sniffer_stream, ¶ms);
+ soup_message_content_sniffed (msg, content_type, params);
+
+ return TRUE;
+}
+
GInputStream *
soup_message_get_request_body_stream (SoupMessage *msg)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]