summaryrefslogtreecommitdiff
path: root/libsoup/soup-request.c
diff options
context:
space:
mode:
Diffstat (limited to 'libsoup/soup-request.c')
-rw-r--r--libsoup/soup-request.c96
1 files changed, 68 insertions, 28 deletions
diff --git a/libsoup/soup-request.c b/libsoup/soup-request.c
index e7471c1c..0dfe3eff 100644
--- a/libsoup/soup-request.c
+++ b/libsoup/soup-request.c
@@ -27,8 +27,6 @@
#include <glib/gi18n-lib.h>
-#define LIBSOUP_USE_UNSTABLE_REQUEST_API
-
#include "soup-request.h"
#include "soup.h"
#include "soup-requester.h"
@@ -37,8 +35,8 @@
* SECTION:soup-request
* @short_description: Protocol-independent streaming request interface
*
- * A #SoupRequest is created by #SoupRequester, and represents a
- * request to retrieve a particular URI.
+ * A #SoupRequest is created by #SoupSession, and represents a request
+ * to retrieve a particular URI.
*/
/**
@@ -46,7 +44,7 @@
*
* A request to retrieve a particular URI.
*
- * Since: 2.34
+ * Since: 2.42
*/
static void soup_request_initable_interface_init (GInitableIface *initable_interface);
@@ -138,7 +136,7 @@ soup_request_initable_init (GInitable *initable,
gboolean ok;
if (!request->priv->uri) {
- g_set_error (error, SOUP_REQUESTER_ERROR, SOUP_REQUESTER_ERROR_BAD_URI,
+ g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI,
_("No URI provided"));
return FALSE;
}
@@ -148,7 +146,7 @@ soup_request_initable_init (GInitable *initable,
if (!ok && error && !*error) {
char *uri_string = soup_uri_to_string (request->priv->uri, FALSE);
- g_set_error (error, SOUP_REQUESTER_ERROR, SOUP_REQUESTER_ERROR_BAD_URI,
+ g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI,
_("Invalid '%s' URI: %s"),
request->priv->uri->scheme,
uri_string);
@@ -173,13 +171,18 @@ soup_request_default_send_async (SoupRequest *request,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *simple;
-
- simple = g_simple_async_result_new (G_OBJECT (request),
- callback, user_data,
- soup_request_default_send_async);
- g_simple_async_result_complete_in_idle (simple);
- g_object_unref (simple);
+ GTask *task;
+ GInputStream *stream;
+ GError *error = NULL;
+
+ task = g_task_new (request, cancellable, callback, user_data);
+
+ stream = soup_request_send (request, cancellable, &error);
+ if (stream)
+ g_task_return_pointer (task, stream, g_object_unref);
+ else
+ g_task_return_error (task, error);
+ g_object_unref (task);
}
static GInputStream *
@@ -187,9 +190,7 @@ soup_request_default_send_finish (SoupRequest *request,
GAsyncResult *result,
GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (request), soup_request_default_send_async), NULL);
-
- return soup_request_send (request, NULL, error);
+ return g_task_propagate_pointer (G_TASK (result), error);
}
/**
@@ -201,10 +202,13 @@ soup_request_default_send_finish (SoupRequest *request,
* Synchronously requests the URI pointed to by @request, and returns
* a #GInputStream that can be used to read its contents.
*
+ * Note that you cannot use this method with #SoupRequests attached to
+ * a #SoupSessionAsync.
+ *
* Return value: (transfer full): a #GInputStream that can be used to
* read from the URI pointed to by @request.
*
- * Since: 2.34
+ * Since: 2.42
*/
GInputStream *
soup_request_send (SoupRequest *request,
@@ -225,7 +229,10 @@ soup_request_send (SoupRequest *request,
* Begins an asynchronously request for the URI pointed to by
* @request.
*
- * Since: 2.34
+ * Note that you cannot use this method with #SoupRequests attached to
+ * a #SoupSessionSync.
+ *
+ * Since: 2.42
*/
void
soup_request_send_async (SoupRequest *request,
@@ -248,7 +255,7 @@ soup_request_send_async (SoupRequest *request,
* Return value: (transfer full): a #GInputStream that can be used to
* read from the URI pointed to by @request.
*
- * Since: 2.34
+ * Since: 2.42
*/
GInputStream *
soup_request_send_finish (SoupRequest *request,
@@ -274,6 +281,20 @@ soup_request_class_init (SoupRequestClass *request_class)
object_class->set_property = soup_request_set_property;
object_class->get_property = soup_request_get_property;
+ /**
+ * SOUP_REQUEST_URI:
+ *
+ * Alias for the #SoupRequest:uri property, qv.
+ *
+ * Since: 2.42
+ */
+ /**
+ * SoupRequest:uri:
+ *
+ * The request URI.
+ *
+ * Since: 2.42
+ */
g_object_class_install_property (
object_class, PROP_URI,
g_param_spec_boxed (SOUP_REQUEST_URI,
@@ -281,6 +302,20 @@ soup_request_class_init (SoupRequestClass *request_class)
"The request URI",
SOUP_TYPE_URI,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ /**
+ * SOUP_REQUEST_SESSION:
+ *
+ * Alias for the #SoupRequest:session property, qv.
+ *
+ * Since: 2.42
+ */
+ /**
+ * SoupRequest:session:
+ *
+ * The request's #SoupSession.
+ *
+ * Since: 2.42
+ */
g_object_class_install_property (
object_class, PROP_SESSION,
g_param_spec_object (SOUP_REQUEST_SESSION,
@@ -304,7 +339,7 @@ soup_request_initable_interface_init (GInitableIface *initable_interface)
*
* Return value: (transfer none): @request's URI
*
- * Since: 2.34
+ * Since: 2.42
*/
SoupURI *
soup_request_get_uri (SoupRequest *request)
@@ -320,7 +355,7 @@ soup_request_get_uri (SoupRequest *request)
*
* Return value: (transfer none): @request's #SoupSession
*
- * Since: 2.34
+ * Since: 2.42
*/
SoupSession *
soup_request_get_session (SoupRequest *request)
@@ -332,12 +367,14 @@ soup_request_get_session (SoupRequest *request)
* soup_request_get_content_length:
* @request: a #SoupRequest
*
- * Gets the length of the data represented by @request.
+ * Gets the length of the data represented by @request. For most
+ * request types, this will not be known until after you call
+ * soup_request_send() or soup_request_send_finish().
*
* Return value: the length of the data represented by @request,
* or -1 if not known.
*
- * Since: 2.34
+ * Since: 2.42
*/
goffset
soup_request_get_content_length (SoupRequest *request)
@@ -349,14 +386,17 @@ soup_request_get_content_length (SoupRequest *request)
* soup_request_get_content_type:
* @request: a #SoupRequest
*
- * Gets the type of the data represented by @request. As in the
- * HTTP Content-Type header, this may include parameters after
- * the MIME type.
+ * Gets the type of the data represented by @request. For most request
+ * types, this will not be known until after you call
+ * soup_request_send() or soup_request_send_finish().
+ *
+ * As in the HTTP Content-Type header, this may include parameters
+ * after the MIME type.
*
* Return value: the type of the data represented by @request,
* or %NULL if not known.
*
- * Since: 2.34
+ * Since: 2.42
*/
const char *
soup_request_get_content_type (SoupRequest *request)