[libsoup/carlosgc/remove-basic-api: 3/3] session: remove the basic APIs




commit b9b421d2e184107eddedd87a072f6df9c5c38e6f
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Mar 4 18:07:49 2021 +0100

    session: remove the basic APIs
    
    Now that we have soup_session_send_and_read() the only difference is
    that we need to build a SoupMessage first.
    
    Fixes #216

 docs/reference/client-basic.xml             |  52 +--
 docs/reference/libsoup-3.0-sections.txt     |   7 -
 docs/reference/migrating-from-libsoup-2.xml |   8 +-
 libsoup/soup-session.c                      | 489 ----------------------------
 libsoup/soup-session.h                      |  41 ---
 tests/session-test.c                        | 179 ----------
 tests/sniffing-test.c                       |  12 -
 7 files changed, 36 insertions(+), 752 deletions(-)
---
diff --git a/docs/reference/client-basic.xml b/docs/reference/client-basic.xml
index 9477a8db..00b6baa4 100644
--- a/docs/reference/client-basic.xml
+++ b/docs/reference/client-basic.xml
@@ -24,29 +24,34 @@
 int main (int argc, char **argv)
 {
     SoupSession *session = soup_session_new ();
-    char *content_type;
+    SoupMessageHeaders *response_headers;
+    const char *content_type;
+    SoupMessage *msg = soup_message_new (SOUP_METHOD_GET, 
"https://upload.wikimedia.org/wikipedia/commons/5/5f/BBB-Bunny.png";);
     GError *error = NULL;
-    GBytes *bytes = soup_session_load_uri_bytes (
+    GBytes *bytes = soup_session_send_and_read (
         session,
-        "https://upload.wikimedia.org/wikipedia/commons/5/5f/BBB-Bunny.png";,
+        msg,
         NULL, // Pass a GCancellable here if you want to cancel a download
-        &content_type,
         &error);
 
     if (error) {
         g_printerr ("Failed to download: %s\n", error->message);
         g_error_free (error);
+        g_object_unref (msg);
         g_object_unref (session);
         return 1;
     }
 
+    response_headers = soup_message_get_response_headers (msg);
+    content_type = soup_message_headers_get_content_type (response_headers);
+
     // content_type = "image/png"
     // bytes contains the raw data that can be used elsewhere
     g_print ("Downloaded %zu bytes of type %s\n",
              g_bytes_get_size (bytes), content_type);
 
-    g_free (content_type);
     g_bytes_unref (bytes);
+    g_object_unref (msg);
     g_object_unref (session);
     return 0;
 }]]>
@@ -63,20 +68,21 @@ int main (int argc, char **argv)
 int main (int argc, char **argv)
 {
     SoupSession *session = soup_session_new ();
-    char *content_type;
+    SoupMessageHeaders *response_headers;
+    const char *content_type;
     goffset content_length;
+    SoupMessage *msg = soup_message_new (SOUP_METHOD_GET, 
"https://upload.wikimedia.org/wikipedia/commons/5/5f/BBB-Bunny.png";);
     GError *error = NULL;
-    GInputStream *in_stream = soup_session_read_uri (
+    GInputStream *in_stream = soup_session_send (
         session,
-        "https://upload.wikimedia.org/wikipedia/commons/5/5f/BBB-Bunny.png";,
+        msg,
         NULL,
-        &content_length,
-        &content_type,
         &error);
 
     if (error) {
         g_printerr ("Failed to download: %s\n", error->message);
         g_error_free (error);
+        g_object_unref (msg);
         g_object_unref (session);
         return 1;
     }
@@ -91,10 +97,15 @@ int main (int argc, char **argv)
         g_error_free (error);
         g_object_unref (output_file);
         g_object_unref (in_stream);
+        g_object_unref (msg);
         g_object_unref (session);
         return 1;
     }
 
+    response_headers = soup_message_get_response_headers (msg);
+    content_type = soup_message_headers_get_content_type (response_headers);
+    content_length = soup_message_headers_get_content_length (response_headers);
+
     // content_type = "image/png"
     g_print ("Downloading %zu bytes of type %s to %s\n",
              content_length, content_type,
@@ -111,10 +122,10 @@ int main (int argc, char **argv)
         g_print ("Download completed\n");
     }
 
-    g_free (content_type);
     g_object_unref (output_file);
     g_object_unref (in_stream);
     g_object_unref (out_stream);
+    g_object_unref (msg);
     g_object_unref (session);
     return error ? 1 : 0;
 }]]>
@@ -125,8 +136,8 @@ int main (int argc, char **argv)
             <title>Using Asynchronously</title>
             <para>If you are using libsoup in an application with a <link 
linkend="GMainLoop"><type>GMainLoop</type></link> such as a GTK application
             you do not want to block the mainloop by doing IO. To accomplish this libsoup provides an
-            asynchronous version of each of the APIs: <link 
linkend="soup-session-load-uri-bytes-async"><function>soup_session_load_uri_bytes_async()</function></link>
-            and <link 
linkend="soup-session-read-uri-async"><function>soup_session_read_uri_async()</function></link>. These behave 
the same as all async GLib
+            asynchronous version of each of the APIs: <link 
linkend="soup-session-send-and-read-async"><function>soup_session_send_and_read_async()</function></link>
+            and <link 
linkend="soup-session-send-async"><function>soup_session_send_async()</function></link>. These behave the 
same as all async GLib
             APIs, for example:</para>
 <informalexample><programlisting><![CDATA[#include <libsoup/soup.h>
 
@@ -134,8 +145,7 @@ static void on_load_callback (GObject *source, GAsyncResult *result, gpointer us
 {
     GMainLoop *loop = user_data;
     GError *error = NULL;
-    GBytes *bytes = soup_session_load_uri_bytes_finish (SOUP_SESSION (source), result,
-                                                        NULL, &error);
+    GBytes *bytes = soup_session_send_and_read_finish (SOUP_SESSION (source), result, &error);
 
     // Usage here is the same as before
     if (error) {
@@ -143,7 +153,7 @@ static void on_load_callback (GObject *source, GAsyncResult *result, gpointer us
     } else {
         g_bytes_unref (bytes);
     }
-    
+
     g_main_loop_quit (loop);
 }
 
@@ -151,21 +161,23 @@ int main (int argc, char **argv)
 {
     SoupSession *session = soup_session_new ();
     GMainLoop *loop = g_main_loop_new (NULL, FALSE);
+    SoupMessage *msg = soup_message_new (SOUP_METHOD_GET, 
"https://upload.wikimedia.org/wikipedia/commons/5/5f/BBB-Bunny.png";);
 
-    soup_session_load_uri_bytes_async (
+    soup_session_send_and_read_async (
         session,
-        "https://upload.wikimedia.org/wikipedia/commons/5/5f/BBB-Bunny.png";,
+        msg,
         G_PRIORITY_DEFAULT,
         NULL,
         on_load_callback,
-        loop); 
+        loop);
 
     g_main_loop_run (loop);
 
     g_main_loop_unref (loop);
+    g_object_unref (msg);
     g_object_unref (session);
     return 0;
 }]]>
 </programlisting></informalexample>
         </sect2>
-</sect1>
\ No newline at end of file
+</sect1>
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt
index 8344ef67..0899c3be 100644
--- a/docs/reference/libsoup-3.0-sections.txt
+++ b/docs/reference/libsoup-3.0-sections.txt
@@ -392,13 +392,6 @@ soup_session_send_and_read
 soup_session_send_and_read_async
 soup_session_send_and_read_finish
 <SUBSECTION>
-soup_session_read_uri
-soup_session_read_uri_async
-soup_session_read_uri_finish
-soup_session_load_uri_bytes
-soup_session_load_uri_bytes_async
-soup_session_load_uri_bytes_finish
-<SUBSECTION>
 soup_session_websocket_connect_async
 soup_session_websocket_connect_finish
 <SUBSECTION>
diff --git a/docs/reference/migrating-from-libsoup-2.xml b/docs/reference/migrating-from-libsoup-2.xml
index 04838338..f16b82ce 100644
--- a/docs/reference/migrating-from-libsoup-2.xml
+++ b/docs/reference/migrating-from-libsoup-2.xml
@@ -34,8 +34,8 @@ linkend="soup-uri-decode-data-uri"><function>soup_uri_decode_data_uri()</functio
                 </listitem>
                 <listitem>
                     <para><type>SoupRequest</type></para>
-                    <para>You should use the new <link 
linkend="soup-session-read-uri"><function>soup_session_read_uri()</function></link> or
-                        <link 
linkend="soup-session-read-uri-async"><function>soup_session_read_uri_async()</function></link> 
methods.</para>
+                    <para>You should use <link 
linkend="soup-session-send"><function>soup_session_send()</function></link> or
+                        <link 
linkend="soup-session-send-async"><function>soup_session_send_async()</function></link> methods.</para>
                 </listitem>
                 <listitem>
                     <para><type>SoupAddress</type> has been replaced with <link 
linkend="GInetAddress"><type>GInetAddress</type></link>
@@ -179,8 +179,8 @@ linkend="soup-uri-decode-data-uri"><function>soup_uri_decode_data_uri()</functio
         <para>libsoup no longer stores a buffer of data for you to read from and instead it returns
             a <link linkend="GInputStream"><type>GInputStream</type></link> which you read from using normal 
GIO APIs.</para>
         <para>If you want to simply request a buffer and nothing more you can use the
-                <link 
linkend="soup_session_load_uri_bytes"><function>soup_session_load_uri_bytes()</function></link> or
-                <link 
linkend="soup_session_load_uri_bytes_async"><function>soup_session_load_uri_bytes_async()</function></link> 
APIs.</para>
+                <link 
linkend="soup_session_send_and_read"><function>soup_session_send_and_read()</function></link> or
+                <link 
linkend="soup_session_send_and_read_async"><function>soup_session_send_and_read_async()</function></link> 
APIs.</para>
         <para>This also applies to writing data where you can set a <link 
linkend="GOutputStream"><type>GOutputStream</type></link> using
                 <link 
linkend="soup_message_set_request_body"><function>soup_message_set_request_body()</function></link> or use 
the convenience API
                 <link 
linkend="soup_message_set_request_body_from_bytes"><function>soup_message_set_request_body_from_bytes()</function></link>
 to use a GBytes
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 5244325c..56ce29e0 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -183,9 +183,6 @@ enum {
  */
 /**
  * SoupSessionError:
- * @SOUP_SESSION_ERROR_BAD_URI: the URI could not be parsed
- * @SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME: the URI scheme is not
- *   supported by this #SoupSession
  * @SOUP_SESSION_ERROR_PARSING: the server's response could not
  *   be parsed
  * @SOUP_SESSION_ERROR_ENCODING: the server's response was in an
@@ -3461,492 +3458,6 @@ soup_session_get_async_result_message (SoupSession  *session,
         return item ? item->msg : NULL;
 }
 
-typedef struct {
-        goffset content_length;
-        char *content_type;
-} SessionGetAsyncData;
-
-static void
-session_get_async_data_free (SessionGetAsyncData *data)
-{
-        g_free (data->content_type);
-        g_slice_free (SessionGetAsyncData, data);
-}
-
-static void
-session_get_async_data_set_content_type (SessionGetAsyncData *data,
-                                         const char          *content_type,
-                                         GHashTable          *params)
-{
-        GString *type;
-
-        type = g_string_new (content_type);
-        if (params) {
-                GHashTableIter iter;
-                gpointer key, value;
-
-                g_hash_table_iter_init (&iter, params);
-                while (g_hash_table_iter_next (&iter, &key, &value)) {
-                        g_string_append (type, "; ");
-                        soup_header_g_string_append_param (type, key, value);
-                }
-        }
-
-        g_free (data->content_type);
-        data->content_type = g_string_free (type, FALSE);
-}
-
-static void
-http_input_stream_ready_cb (SoupSession  *session,
-                            GAsyncResult *result,
-                            GTask        *task)
-{
-        GInputStream *stream;
-        GError *error = NULL;
-
-        stream = soup_session_send_finish (session, result, &error);
-        if (stream)
-                g_task_return_pointer (task, stream, g_object_unref);
-        else
-                g_task_return_error (task, error);
-        g_object_unref (task);
-}
-
-static void
-get_http_content_sniffed (SoupMessage         *msg,
-                          const char          *content_type,
-                          GHashTable          *params,
-                          SessionGetAsyncData *data)
-{
-        session_get_async_data_set_content_type (data, content_type, params);
-}
-
-static void
-get_http_got_headers (SoupMessage         *msg,
-                      SessionGetAsyncData *data)
-{
-        goffset content_length;
-        const char *content_type;
-        GHashTable *params = NULL;
-
-        content_length = soup_message_headers_get_content_length (soup_message_get_response_headers (msg));
-        data->content_length = content_length != 0 ? content_length : -1;
-        content_type = soup_message_headers_get_content_type (soup_message_get_response_headers (msg), 
&params);
-        session_get_async_data_set_content_type (data, content_type, params);
-        g_clear_pointer (&params, g_hash_table_destroy);
-}
-
-/**
- * soup_session_read_uri_async:
- * @session: a #SoupSession
- * @uri: a URI, in string form
- * @io_priority: the I/O priority of the request
- * @cancellable: a #GCancellable
- * @callback: the callback to invoke
- * @user_data: data for @callback
- *
- * Asynchronously retrieve @uri.
- *
- * If the given @uri is not HTTP it will fail with %SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME
- * error.
- *
- * When the operation is finished, @callback will be called. You can then
- * call soup_session_read_uri_finish() to get the result of the operation.
- */
-void
-soup_session_read_uri_async (SoupSession        *session,
-                             const char         *uri,
-                             int                 io_priority,
-                             GCancellable       *cancellable,
-                             GAsyncReadyCallback callback,
-                             gpointer            user_data)
-{
-        GTask *task;
-        GUri *soup_uri;
-        SoupMessage *msg;
-        GError *error = NULL;
-        SessionGetAsyncData *data;
-
-        g_return_if_fail (SOUP_IS_SESSION (session));
-        g_return_if_fail (uri != NULL);
-
-        task = g_task_new (session, cancellable, callback, user_data);
-        g_task_set_priority (task, io_priority);
-
-        soup_uri = g_uri_parse (uri, SOUP_HTTP_URI_FLAGS, &error);
-        if (!soup_uri) {
-                g_task_return_new_error (task,
-                                         SOUP_SESSION_ERROR,
-                                         SOUP_SESSION_ERROR_BAD_URI,
-                                         _("Could not parse URI “%s”: %s"),
-                                         uri,
-                                         error->message);
-                g_error_free (error);
-                g_object_unref (task);
-                return;
-        }
-
-        if (!soup_uri_is_http (soup_uri) && !soup_uri_is_https (soup_uri)) {
-                g_task_return_new_error (task,
-                                         SOUP_SESSION_ERROR,
-                                         SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME,
-                                         _("Unsupported URI scheme “%s”"),
-                                         g_uri_get_scheme (soup_uri));
-                g_object_unref (task);
-                g_uri_unref (soup_uri);
-                return;
-        }
-
-        if (!SOUP_URI_IS_VALID (soup_uri)) {
-                g_task_return_new_error (task,
-                                         SOUP_SESSION_ERROR,
-                                         SOUP_SESSION_ERROR_BAD_URI,
-                                         _("Invalid “%s” URI: %s"),
-                                         g_uri_get_scheme (soup_uri),
-                                         uri);
-                g_object_unref (task);
-                g_uri_unref (soup_uri);
-                return;
-        }
-
-        data = g_slice_new0 (SessionGetAsyncData);
-        g_task_set_task_data (task, data, (GDestroyNotify)session_get_async_data_free);
-
-        msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri);
-        g_signal_connect (msg, "content-sniffed",
-                          G_CALLBACK (get_http_content_sniffed), data);
-        g_signal_connect (msg, "got-headers",
-                          G_CALLBACK (get_http_got_headers), data);
-        soup_session_send_async (session, msg,
-                                 g_task_get_priority (task),
-                                 g_task_get_cancellable (task),
-                                 (GAsyncReadyCallback)http_input_stream_ready_cb,
-                                 task);
-        g_object_unref (msg);
-        g_uri_unref (soup_uri);
-}
-
-/**
- * soup_session_read_uri_finish:
- * @session: a #SoupSession
- * @result: the #GAsyncResult passed to your callback
- * @content_length: (out) (nullable): location to store content length, or %NULL
- * @content_type: (out) (nullable) (transfer full): location to store content type, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Finish an asynchronous operation started by soup_session_read_uri_async().
- * If the content length is unknown -1 is returned in @content_length.
- *
- * Returns: (transfer full): a #GInputStream to read the contents from,
- *    or %NULL in case of error.
- */
-GInputStream *
-soup_session_read_uri_finish (SoupSession  *session,
-                              GAsyncResult *result,
-                              goffset      *content_length,
-                              char        **content_type,
-                              GError      **error)
-{
-        GTask *task;
-
-        g_return_val_if_fail (SOUP_IS_SESSION (session), NULL);
-        g_return_val_if_fail (g_task_is_valid (result, session), NULL);
-
-        task = G_TASK (result);
-
-        if (!g_task_had_error (task) && (content_length || content_type)) {
-                SessionGetAsyncData *data;
-
-                data = g_task_get_task_data (task);
-                if (content_length)
-                        *content_length = data->content_length;
-                if (content_type)
-                        *content_type = g_steal_pointer (&data->content_type);
-        }
-
-        return g_task_propagate_pointer (task, error);
-}
-
-/**
- * soup_session_read_uri:
- * @session: a #SoupSession
- * @uri: a URI, in string form
- * @cancellable: a #GCancellable
- * @content_length: (out) (nullable): location to store content length, or %NULL
- * @content_type: (out) (nullable) (transfer full): location to store content type, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Synchronously retrieve @uri and return a #GInputStream to read the contents.
- * If the content length is unknown -1 is returned in @content_length.
- *
- * If the given @uri is not HTTP it will fail with %SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME
- * error.
- *
- * Returns: (transfer full): a #GInputStream to read the contents from,
- *    or %NULL in case of error.
- */
-GInputStream *
-soup_session_read_uri (SoupSession  *session,
-                       const char   *uri,
-                       GCancellable *cancellable,
-                       goffset      *content_length,
-                       char        **content_type,
-                       GError      **error)
-{
-        GUri *soup_uri;
-        SoupMessage *msg;
-        GInputStream *stream;
-        GError *internal_error = NULL;
-        SessionGetAsyncData data = { 0, NULL };
-
-        g_return_val_if_fail (SOUP_IS_SESSION (session), NULL);
-        g_return_val_if_fail (uri != NULL, NULL);
-
-        soup_uri = g_uri_parse (uri, SOUP_HTTP_URI_FLAGS, &internal_error);
-        if (!soup_uri) {
-                g_set_error (error,
-                             SOUP_SESSION_ERROR,
-                             SOUP_SESSION_ERROR_BAD_URI,
-                             _("Could not parse URI “%s”: %s"),
-                             uri,
-                             internal_error->message);
-                g_error_free (internal_error);
-
-                return NULL;
-        }
-
-        if (!soup_uri_is_http (soup_uri) && !soup_uri_is_https (soup_uri)) {
-                g_set_error (error,
-                             SOUP_SESSION_ERROR,
-                             SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME,
-                             _("Unsupported URI scheme “%s”"),
-                             g_uri_get_scheme (soup_uri));
-                g_uri_unref (soup_uri);
-
-                return NULL;
-        }
-
-        if (!SOUP_URI_IS_VALID (soup_uri)) {
-                g_set_error (error,
-                             SOUP_SESSION_ERROR,
-                             SOUP_SESSION_ERROR_BAD_URI,
-                             _("Invalid “%s” URI: %s"),
-                             g_uri_get_scheme (soup_uri),
-                             uri);
-                g_uri_unref (soup_uri);
-
-                return NULL;
-        }
-
-        msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri);
-        g_signal_connect (msg, "content-sniffed",
-                          G_CALLBACK (get_http_content_sniffed), &data);
-        g_signal_connect (msg, "got-headers",
-                          G_CALLBACK (get_http_got_headers), &data);
-        stream = soup_session_send (session, msg, cancellable, error);
-        if (stream) {
-                if (content_length)
-                        *content_length = data.content_length;
-                if (content_type) {
-                        *content_type = data.content_type;
-                        data.content_type = NULL;
-                }
-        }
-
-        g_free (data.content_type);
-        g_uri_unref (soup_uri);
-
-        return stream;
-}
-
-static void
-session_load_uri_async_splice_ready_cb (GOutputStream *ostream,
-                                        GAsyncResult  *result,
-                                        GTask         *task)
-{
-        GError *error = NULL;
-
-        if (g_output_stream_splice_finish (ostream, result, &error) != -1) {
-                g_task_return_pointer (task,
-                                       g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM 
(ostream)),
-                                       (GDestroyNotify)g_bytes_unref);
-        } else {
-                g_task_return_error (task, error);
-        }
-        g_object_unref (task);
-}
-
-static void
-session_read_uri_async_ready_cb (SoupSession  *session,
-                                 GAsyncResult *result,
-                                 GTask        *task)
-{
-        GInputStream *stream;
-        goffset content_length = 0;
-        char *content_type = NULL;
-        GOutputStream *ostream;
-        GError *error = NULL;
-
-        stream = soup_session_read_uri_finish (session, result, &content_length, &content_type, &error);
-        if (!stream) {
-                g_task_return_error (task, error);
-                g_object_unref (task);
-
-                return;
-        }
-
-        g_task_set_task_data (task, content_type, g_free);
-
-        if (content_length == 0) {
-                g_task_return_pointer (task,
-                                       g_bytes_new_static (NULL, 0),
-                                       (GDestroyNotify)g_bytes_unref);
-                g_object_unref (task);
-                g_object_unref (stream);
-
-                return;
-        }
-
-        ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
-        g_output_stream_splice_async (ostream,
-                                      stream,
-                                      G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
-                                      G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
-                                      g_task_get_priority (task),
-                                      g_task_get_cancellable (task),
-                                      (GAsyncReadyCallback)session_load_uri_async_splice_ready_cb,
-                                      task);
-        g_object_unref (ostream);
-        g_object_unref (stream);
-}
-
-/**
- * soup_session_load_uri_bytes_async:
- * @session: a #SoupSession
- * @uri: a URI, in string form
- * @io_priority: the I/O priority of the request
- * @cancellable: a #GCancellable
- * @callback: the callback to invoke
- * @user_data: data for @callback
- *
- * Asynchronously retrieve @uri to be returned as a #GBytes. This function
- * is like soup_session_read_uri_async() but the contents are read and returned
- * as a #GBytes. It should only be used when the resource to be retireved
- * is not too long and can be stored in memory.
- *
- * If the given @uri is not HTTP it will fail with %SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME
- * error.
- *
- * When the operation is finished, @callback will be called. You can then
- * call soup_session_load_uri_bytes_finish() to get the result of the operation.
- */
-void
-soup_session_load_uri_bytes_async (SoupSession        *session,
-                                   const char         *uri,
-                                   int                 io_priority,
-                                   GCancellable       *cancellable,
-                                   GAsyncReadyCallback callback,
-                                   gpointer            user_data)
-{
-        GTask *task;
-
-        g_return_if_fail (SOUP_IS_SESSION (session));
-        g_return_if_fail (uri != NULL);
-
-        task = g_task_new (session, cancellable, callback, user_data);
-        g_task_set_priority (task, io_priority);
-        soup_session_read_uri_async (session, uri, io_priority, cancellable,
-                                     (GAsyncReadyCallback)session_read_uri_async_ready_cb,
-                                     task);
-}
-
-/**
- * soup_session_load_uri_bytes_finish:
- * @session: a #SoupSession
- * @result: the #GAsyncResult passed to your callback
- * @content_type: (out) (nullable) (transfer full): location to store content type, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Finish an asynchronous operation started by soup_session_load_uri_bytes_async().
- *
- * Returns: (transfer full): a #GBytes with the contents, or %NULL in case of error.
- */
-GBytes *
-soup_session_load_uri_bytes_finish (SoupSession  *session,
-                                    GAsyncResult *result,
-                                    char        **content_type,
-                                    GError      **error)
-{
-        GTask *task;
-
-        g_return_val_if_fail (SOUP_IS_SESSION (session), NULL);
-        g_return_val_if_fail (g_task_is_valid (result, session), NULL);
-
-        task = G_TASK (result);
-
-        if (!g_task_had_error (task) && content_type)
-                *content_type = g_strdup (g_task_get_task_data (task));
-
-        return g_task_propagate_pointer (task, error);
-}
-
-/**
- * soup_session_load_uri_bytes:
- * @session: a #SoupSession
- * @uri: a URI, in string form
- * @cancellable: a #GCancellable
- * @content_type: (out) (nullable) (transfer full): location to store content type, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Synchronously retrieve @uri to be returned as a #GBytes. This function
- * is like soup_session_read_uri() but the contents are read and returned
- * as a #GBytes. It should only be used when the resource to be retireved
- * is not too long and can be stored in memory.
- *
- * If the given @uri is not HTTP it will fail with %SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME
- * error.
- *
- * Returns: (transfer full): a #GBytes with the contents, or %NULL in case of error.
- */
-GBytes *
-soup_session_load_uri_bytes (SoupSession  *session,
-                             const char   *uri,
-                             GCancellable *cancellable,
-                             char        **content_type,
-                             GError      **error)
-{
-        GInputStream *stream;
-        GOutputStream *ostream;
-        goffset content_length;
-        GBytes *bytes = NULL;
-
-        g_return_val_if_fail (SOUP_IS_SESSION (session), NULL);
-        g_return_val_if_fail (uri != NULL, NULL);
-
-        stream = soup_session_read_uri (session, uri, cancellable, &content_length, content_type, error);
-        if (!stream)
-                return NULL;
-
-        if (content_length == 0) {
-                g_object_unref (stream);
-
-                return g_bytes_new_static (NULL, 0);
-        }
-
-        ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
-        if (g_output_stream_splice (ostream,
-                                    stream,
-                                    G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
-                                    G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
-                                    cancellable, error) != -1) {
-                bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (ostream));
-        }
-        g_object_unref (ostream);
-        g_object_unref (stream);
-
-        return bytes;
-}
-
 static GIOStream *
 steal_connection (SoupSession          *session,
                   SoupMessageQueueItem *item)
diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h
index 446fd91e..85a5a420 100644
--- a/libsoup/soup-session.h
+++ b/libsoup/soup-session.h
@@ -20,8 +20,6 @@ GQuark soup_session_error_quark (void);
 #define SOUP_SESSION_ERROR soup_session_error_quark ()
 
 typedef enum {
-       SOUP_SESSION_ERROR_BAD_URI,
-       SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME,
        SOUP_SESSION_ERROR_PARSING,
        SOUP_SESSION_ERROR_ENCODING,
        SOUP_SESSION_ERROR_TOO_MANY_REDIRECTS,
@@ -170,45 +168,6 @@ SoupSessionFeature *soup_session_get_feature_for_message(SoupSession        *ses
                                                         GType               feature_type,
                                                         SoupMessage        *msg);
 
-SOUP_AVAILABLE_IN_ALL
-GInputStream       *soup_session_read_uri               (SoupSession        *session,
-                                                        const char         *uri,
-                                                        GCancellable       *cancellable,
-                                                        goffset            *content_length,
-                                                        char              **content_type,
-                                                        GError            **error);
-SOUP_AVAILABLE_IN_ALL
-void                soup_session_read_uri_async         (SoupSession        *session,
-                                                        const char         *uri,
-                                                        int                 io_priority,
-                                                        GCancellable       *cancellable,
-                                                        GAsyncReadyCallback callback,
-                                                        gpointer            user_data);
-SOUP_AVAILABLE_IN_ALL
-GInputStream       *soup_session_read_uri_finish        (SoupSession        *session,
-                                                        GAsyncResult       *result,
-                                                        goffset            *content_length,
-                                                        char              **content_type,
-                                                        GError            **error);
-SOUP_AVAILABLE_IN_ALL
-GBytes             *soup_session_load_uri_bytes         (SoupSession        *session,
-                                                        const char         *uri,
-                                                        GCancellable       *cancellable,
-                                                        char              **content_type,
-                                                        GError            **error);
-SOUP_AVAILABLE_IN_ALL
-void                soup_session_load_uri_bytes_async   (SoupSession        *session,
-                                                        const char         *uri,
-                                                        int                 io_priority,
-                                                        GCancellable       *cancellable,
-                                                        GAsyncReadyCallback callback,
-                                                        gpointer            user_data);
-SOUP_AVAILABLE_IN_ALL
-GBytes             *soup_session_load_uri_bytes_finish  (SoupSession        *session,
-                                                        GAsyncResult       *result,
-                                                        char              **content_type,
-                                                        GError            **error);
-
 SOUP_AVAILABLE_IN_ALL
 void                     soup_session_websocket_connect_async  (SoupSession          *session,
                                                                SoupMessage          *msg,
diff --git a/tests/session-test.c b/tests/session-test.c
index 6d25f7d0..aba7fdd9 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -419,172 +419,6 @@ do_queue_order_test (void)
        soup_test_session_abort_unref (session);
 }
 
-typedef enum {
-        SYNC = 1 << 0,
-        STREAM = 1 << 1
-} GetTestFlags;
-
-typedef struct {
-        GMainLoop *loop;
-        GBytes *body;
-        char *content_type;
-        GError *error;
-} GetAsyncData;
-
-static GBytes *
-stream_to_bytes (GInputStream *stream)
-{
-        GOutputStream *ostream;
-        GBytes *bytes;
-
-        ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
-        g_output_stream_splice (ostream,
-                                stream,
-                                G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
-                                G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
-                                NULL, NULL);
-        bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (ostream));
-        g_object_unref (ostream);
-
-        return bytes;
-}
-
-static void
-read_uri_async_ready_cb (SoupSession  *session,
-                         GAsyncResult *result,
-                         GetAsyncData *data)
-{
-        GInputStream *stream;
-        goffset content_length;
-
-        stream = soup_session_read_uri_finish (session, result,
-                                               &content_length,
-                                               &data->content_type,
-                                               &data->error);
-        if (stream) {
-                data->body = stream_to_bytes (stream);
-                if (content_length != -1)
-                        g_assert_cmpint (g_bytes_get_size (data->body), ==, content_length);
-                g_object_unref (stream);
-        }
-
-        g_main_loop_quit (data->loop);
-}
-
-static void
-load_uri_bytes_async_ready_cb (SoupSession  *session,
-                               GAsyncResult *result,
-                               GetAsyncData *data)
-{
-        data->body = soup_session_load_uri_bytes_finish (session, result,
-                                                         &data->content_type,
-                                                         &data->error);
-        g_main_loop_quit (data->loop);
-}
-
-static void
-do_read_uri_test (gconstpointer data)
-{
-        GUri *uri;
-        char *uri_string;
-        SoupSession *session;
-        GBytes *body = NULL;
-        char *content_type = NULL;
-        GError *error = NULL;
-        GetTestFlags flags = GPOINTER_TO_UINT (data);
-
-        session = soup_test_session_new (NULL);
-
-        uri = g_uri_parse_relative (base_uri, "/index.txt", SOUP_HTTP_URI_FLAGS, NULL);
-        uri_string = g_uri_to_string (uri);
-
-        if (flags & SYNC) {
-                if (flags & STREAM) {
-                        GInputStream *stream;
-                        goffset content_length = 0;
-
-                        stream = soup_session_read_uri (session, uri_string, NULL,
-                                                        &content_length,
-                                                        &content_type,
-                                                        &error);
-                        body = stream_to_bytes (stream);
-                        if (content_length != -1)
-                                g_assert_cmpint (g_bytes_get_size (body), ==, content_length);
-                        g_object_unref (stream);
-                } else {
-                        body = soup_session_load_uri_bytes (session, uri_string, NULL,
-                                                            &content_type, &error);
-                }
-        } else {
-                GetAsyncData data;
-                GMainContext *context;
-
-                memset (&data, 0, sizeof (GetAsyncData));
-
-                context = g_main_context_get_thread_default ();
-                data.loop = g_main_loop_new (context, TRUE);
-                if (flags & STREAM) {
-                        soup_session_read_uri_async (session, uri_string, G_PRIORITY_DEFAULT, NULL,
-                                                     (GAsyncReadyCallback)read_uri_async_ready_cb,
-                                                     &data);
-                } else {
-                        soup_session_load_uri_bytes_async (session, uri_string, G_PRIORITY_DEFAULT, NULL,
-                                                           
(GAsyncReadyCallback)load_uri_bytes_async_ready_cb,
-                                                           &data);
-                }
-                g_main_loop_run (data.loop);
-                while (g_main_context_pending (context))
-                        g_main_context_iteration (context, FALSE);
-                g_main_loop_unref (data.loop);
-
-                body = data.body;
-                content_type = data.content_type;
-                if (data.error)
-                        g_propagate_error (&error, data.error);
-        }
-
-        g_assert_no_error (error);
-        g_assert_nonnull (body);
-        g_assert_cmpstr (content_type, ==, "text/plain");
-        g_assert_cmpmem (g_bytes_get_data (body, NULL), g_bytes_get_size (body),
-                         g_bytes_get_data (index_bytes, NULL), g_bytes_get_size (index_bytes));
-
-        g_bytes_unref (body);
-        g_free (content_type);
-        g_free (uri_string);
-        g_uri_unref (uri);
-
-        soup_test_session_abort_unref (session);
-}
-
-static struct {
-        const char *uri;
-        int expected_error;
-} get_error_tests[] = {
-        { "./foo", SOUP_SESSION_ERROR_BAD_URI },
-        { "http:/localhost/", SOUP_SESSION_ERROR_BAD_URI },
-        { "foo://host/path", SOUP_SESSION_ERROR_UNSUPPORTED_URI_SCHEME }
-};
-
-static void
-do_load_uri_error_tests (void)
-{
-        SoupSession *session;
-        guint i;
-
-        session = soup_test_session_new (NULL);
-
-        for (i = 0; i < G_N_ELEMENTS (get_error_tests); i++) {
-                GError *error = NULL;
-
-                g_assert_null (soup_session_load_uri_bytes (session, get_error_tests[i].uri, NULL, NULL, 
&error));
-                g_assert_error (error, SOUP_SESSION_ERROR, get_error_tests[i].expected_error);
-                g_error_free (error);
-        }
-
-        soup_test_session_abort_unref (session);
-}
-
 int
 main (int argc, char **argv)
 {
@@ -604,19 +438,6 @@ main (int argc, char **argv)
        g_test_add_func ("/session/property", do_property_tests);
        g_test_add_func ("/session/features", do_features_test);
        g_test_add_func ("/session/queue-order", do_queue_order_test);
-       g_test_add_data_func ("/session/read-uri/async",
-                             GINT_TO_POINTER (STREAM),
-                             do_read_uri_test);
-       g_test_add_data_func ("/session/read-uri/sync",
-                             GINT_TO_POINTER (SYNC | STREAM),
-                             do_read_uri_test);
-       g_test_add_data_func ("/session/load-uri/async",
-                             GINT_TO_POINTER (0),
-                             do_read_uri_test);
-       g_test_add_data_func ("/session/load-uri/sync",
-                             GINT_TO_POINTER (SYNC),
-                             do_read_uri_test);
-       g_test_add_func ("/session/load-uri/errors", do_load_uri_error_tests);
 
        ret = g_test_run ();
 
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c
index 23e05c1a..3a7f4229 100644
--- a/tests/sniffing-test.c
+++ b/tests/sniffing-test.c
@@ -285,8 +285,6 @@ test_sniffing (const char *path, const char *expected_type)
        SoupMessage *msg;
        GBytes *body;
        char *sniffed_type = NULL;
-       char *uri_string;
-       GError *error = NULL;
 
        uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
@@ -299,16 +297,6 @@ test_sniffing (const char *path, const char *expected_type)
        g_free (sniffed_type);
        g_bytes_unref (body);
        g_object_unref (msg);
-
-       sniffed_type = NULL;
-       uri_string = g_uri_to_string (uri);
-       body = soup_session_load_uri_bytes (session, uri_string, NULL, &sniffed_type, &error);
-       g_assert_no_error (error);
-       g_assert_cmpstr (sniffed_type, ==, expected_type);
-       g_free (sniffed_type);
-       g_free (uri_string);
-       g_bytes_unref (body);
-
        g_uri_unref (uri);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]