From d32453cd746839a4acaa00b7ac9eeffe45813d99 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Mon, 19 Oct 2020 13:26:15 +0200 Subject: Remove SoupRequest API --- docs/reference/libsoup-3.0-docs.xml | 9 - docs/reference/libsoup-3.0-sections.txt | 86 ------- docs/reference/meson.build | 1 - docs/reference/request-howto.xml | 180 -------------- libsoup/meson.build | 8 - libsoup/soup-message-io.c | 8 +- libsoup/soup-message-private.h | 3 - libsoup/soup-message.c | 38 +-- libsoup/soup-message.h | 3 - libsoup/soup-request-data.c | 169 ------------- libsoup/soup-request-data.h | 32 --- libsoup/soup-request-file.c | 394 ------------------------------- libsoup/soup-request-file.h | 35 --- libsoup/soup-request-http.c | 243 ------------------- libsoup/soup-request-http.h | 35 --- libsoup/soup-request.c | 404 -------------------------------- libsoup/soup-request.h | 85 ------- libsoup/soup-session.c | 255 +------------------- libsoup/soup-session.h | 30 --- libsoup/soup.h | 4 - tests/meson.build | 1 - tests/resource-test.c | 221 ----------------- tests/session-test.c | 9 - 23 files changed, 11 insertions(+), 2242 deletions(-) delete mode 100644 docs/reference/request-howto.xml delete mode 100644 libsoup/soup-request-data.c delete mode 100644 libsoup/soup-request-data.h delete mode 100644 libsoup/soup-request-file.c delete mode 100644 libsoup/soup-request-file.h delete mode 100644 libsoup/soup-request-http.c delete mode 100644 libsoup/soup-request-http.h delete mode 100644 libsoup/soup-request.c delete mode 100644 libsoup/soup-request.h delete mode 100644 tests/resource-test.c diff --git a/docs/reference/libsoup-3.0-docs.xml b/docs/reference/libsoup-3.0-docs.xml index adb0d12c..8f1ed18d 100644 --- a/docs/reference/libsoup-3.0-docs.xml +++ b/docs/reference/libsoup-3.0-docs.xml @@ -14,18 +14,9 @@ Tutorial - - - Request API - - - - - - Core HTTP API diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt index aa89d8c0..0032e4f3 100644 --- a/docs/reference/libsoup-3.0-sections.txt +++ b/docs/reference/libsoup-3.0-sections.txt @@ -32,7 +32,6 @@ soup_message_get_flags soup_message_disable_feature soup_message_is_feature_disabled -soup_message_get_soup_request SoupMessagePriority soup_message_get_priority @@ -402,13 +401,6 @@ SoupSessionError soup_session_new soup_session_new_with_options -soup_session_request -soup_session_request_uri -soup_session_request_http -soup_session_request_http_uri -SoupRequestError -SOUP_REQUEST_ERROR - soup_session_cancel_message soup_session_send @@ -470,7 +462,6 @@ SOUP_TYPE_SESSION SOUP_SESSION_ERROR SoupSessionClass soup_session_get_type -soup_request_error_quark soup_session_error_quark SoupSocket @@ -909,83 +900,6 @@ SoupContentDecoderPrivate soup_content_decoder_get_type -
-soup-request -SoupRequest -SoupRequest -soup_request_send -soup_request_send_async -soup_request_send_finish - -soup_request_get_content_length -soup_request_get_content_type -soup_request_get_session -soup_request_get_uri - -SOUP_REQUEST_SESSION -SOUP_REQUEST_URI - -SOUP_IS_REQUEST -SOUP_IS_REQUEST_CLASS -SOUP_REQUEST -SOUP_REQUEST_CLASS -SOUP_REQUEST_GET_CLASS -SOUP_TYPE_REQUEST -SoupRequestClass -SoupRequestPrivate -soup_request_get_type -
- -
-soup-request-data -SoupRequestData -SoupRequestData - -SOUP_IS_REQUEST_DATA -SOUP_IS_REQUEST_DATA_CLASS -SOUP_REQUEST_DATA -SOUP_REQUEST_DATA_CLASS -SOUP_REQUEST_DATA_GET_CLASS -SOUP_TYPE_REQUEST_DATA -SoupRequestDataClass -SoupRequestDataPrivate -soup_request_data_get_type -
- -
-soup-request-file -SoupRequestFile -SoupRequestFile -soup_request_file_get_file - -SOUP_IS_REQUEST_FILE -SOUP_IS_REQUEST_FILE_CLASS -SOUP_REQUEST_FILE -SOUP_REQUEST_FILE_CLASS -SOUP_REQUEST_FILE_GET_CLASS -SOUP_TYPE_REQUEST_FILE -SoupRequestFileClass -SoupRequestFilePrivate -soup_request_file_get_type -
- -
-soup-request-http -SoupRequestHTTP -SoupRequestHTTP -soup_request_http_get_message - -SOUP_IS_REQUEST_HTTP -SOUP_IS_REQUEST_HTTP_CLASS -SOUP_REQUEST_HTTP -SOUP_REQUEST_HTTP_CLASS -SOUP_REQUEST_HTTP_GET_CLASS -SOUP_TYPE_REQUEST_HTTP -SoupRequestHTTPClass -SoupRequestHTTPPrivate -soup_request_http_get_type -
-
soup-tld SoupTLD diff --git a/docs/reference/meson.build b/docs/reference/meson.build index 3141b9ac..d5f499ec 100644 --- a/docs/reference/meson.build +++ b/docs/reference/meson.build @@ -64,7 +64,6 @@ gnome.gtkdoc('libsoup-3.0', content_files: [ 'build-howto.xml', 'client-howto.xml', - 'request-howto.xml', 'server-howto.xml' ] ) diff --git a/docs/reference/request-howto.xml b/docs/reference/request-howto.xml deleted file mode 100644 index 1a8b0983..00000000 --- a/docs/reference/request-howto.xml +++ /dev/null @@ -1,180 +0,0 @@ - - - - -libsoup Client SoupRequest API -3 -LIBSOUP Library - - - -libsoup Client SoupRequest APIUsing -libsoup with a mix of http and non-http URIs. - - - -<type>SoupRequest</type> - - -SoupRequest is an -abstract type representing a request for a particular URI. The -SoupRequest API is an alternative to the SoupMessage-based SoupSession APIs which may be -useful to programs that want to deal with multiple kinds of URIs. - - - -SoupRequest officially became part of the -libsoup API in 2.42 with the addition of -soup_session_request -and the related functions. - - - -Additionally, before libsoup 2.42, the -SoupRequest API was the only way to stream an HTTP -response body via GInputStream. As of 2.42, -there are streaming APIs based on SoupMessage (soup_session_send -and soup_session_send_async), -so applications that are using SoupRequest with only -http and https URIs can be -ported to those APIs now. - - - - - -Creating a SoupRequest - - -There are four SoupSession methods for creating -SoupRequests: - - - - - - soup_session_request - takes an arbitrary URI as a string, and returns a SoupRequest. - - - - - soup_session_request_uri - takes an arbitrary URI as a SoupURI, - and returns a SoupRequest. - - - - - soup_session_request_http - takes an HTTP method and an http or https URI as a string, and returns a SoupRequestHTTP. - - - - - soup_session_request_http_uri - takes an HTTP method and an http or https URI as a SoupURI, - and returns a SoupRequestHTTP. - - - - - - - -Sending a SoupRequest - - -Once you have created a SoupRequest, you can send it with -either soup_request_send -or soup_request_send_async. -This will provide you with a GInputStream which you can -read to get the response body. - - - -After sending, you can use soup_request_get_content_length -and soup_request_get_content_type -to get information about the response body. - - - -As with the streaming SoupMessage-based APIs, -soup_request_send and -soup_request_send_async only return errors if a -transport-level problem occurs (eg, it could not connect to the host, -or the request was cancelled). In the case of an HTTP request, use the -message's status_code field to determine -whether the request was successful or not at the HTTP level (ie, "200 -OK" vs "401 Bad Request"). (You can call soup_request_http_get_message -to get the request's corresponding SoupMessage, to look at the -status code or other HTTP metadata.) - - - - - -Supported URI types, and adding your own - - -Different URI types are implemented by different subclasses of -SoupRequest. libsoup currently -implements three SoupRequest classes: - - - - - SoupRequestHTTP - - Handles http and - https URI. - - - - SoupRequestData - - Handles data URIs containing inline data. - - - - SoupRequestFile - - Handles file and - resource URIs. - If you request a URI corresponding to a directory, this - will generate an HTML listing of the directory. - - - - - -You can add additional URI types by implementing your own -SoupRequest subclass; set the -SoupRequestClass's schemes -field to point to a NULL-terminated array of scheme -names, implement the various SoupRequest methods, and -then register the type with your SoupSession by calling -soup_session_add_feature_by_type -and passing the GType of -your request class. - - - - - diff --git a/libsoup/meson.build b/libsoup/meson.build index 3a700870..e8bf6f43 100644 --- a/libsoup/meson.build +++ b/libsoup/meson.build @@ -74,10 +74,6 @@ soup_sources = [ 'soup-misc.c', 'soup-multipart.c', 'soup-multipart-input-stream.c', - 'soup-request.c', - 'soup-request-data.c', - 'soup-request-file.c', - 'soup-request-http.c', 'soup-session.c', 'soup-session-feature.c', 'soup-socket.c', @@ -137,10 +133,6 @@ soup_introspection_headers = [ 'soup-method.h', 'soup-multipart.h', 'soup-multipart-input-stream.h', - 'soup-request.h', - 'soup-request-data.h', - 'soup-request-file.h', - 'soup-request-http.h', 'soup-session.h', 'soup-session-feature.h', 'soup-status.h', diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c index feb88672..9387aafd 100644 --- a/libsoup/soup-message-io.c +++ b/libsoup/soup-message-io.c @@ -483,8 +483,8 @@ parse_headers (SoupMessage *msg, &version, &msg->status_code, &msg->reason_phrase)) { - g_set_error_literal (error, SOUP_REQUEST_ERROR, - SOUP_REQUEST_ERROR_PARSING, + g_set_error_literal (error, SOUP_SESSION_ERROR, + SOUP_SESSION_ERROR_PARSING, _("Could not parse HTTP response")); return SOUP_STATUS_MALFORMED; } @@ -506,8 +506,8 @@ parse_headers (SoupMessage *msg, *encoding = soup_message_headers_get_encoding (msg->response_headers); if (*encoding == SOUP_ENCODING_UNRECOGNIZED) { - g_set_error_literal (error, SOUP_REQUEST_ERROR, - SOUP_REQUEST_ERROR_ENCODING, + g_set_error_literal (error, SOUP_SESSION_ERROR, + SOUP_SESSION_ERROR_ENCODING, _("Unrecognized HTTP response encoding")); return SOUP_STATUS_MALFORMED; } diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h index 21b3a07f..98e862a5 100644 --- a/libsoup/soup-message-private.h +++ b/libsoup/soup-message-private.h @@ -134,9 +134,6 @@ GInputStream *soup_message_setup_body_istream (GInputStream *body_stream, SoupSession *session, SoupProcessingStage start_at_stage); -void soup_message_set_soup_request (SoupMessage *msg, - SoupRequest *req); - SoupConnection *soup_message_get_connection (SoupMessage *msg); void soup_message_set_connection (SoupMessage *msg, SoupConnection *conn); diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c index 0a265dea..3b327413 100644 --- a/libsoup/soup-message.c +++ b/libsoup/soup-message.c @@ -26,12 +26,7 @@ * * You would create a #SoupMessage with soup_message_new() or * soup_message_new_from_uri(), set up its - * fields appropriately, and send it. If you are using the newer - * #SoupRequest API, you would create a request with - * soup_session_request_http() or soup_session_request_http_uri(), and - * the returned #SoupRequestHTTP will already have an associated - * #SoupMessage that you can retrieve via - * soup_request_http_get_message(). + * fields appropriately, and send it. * * Note that libsoup's terminology here does not quite match the HTTP * specification: in RFC 2616, an "HTTP-message" is @@ -1745,37 +1740,6 @@ soup_message_get_https_status (SoupMessage *msg, return priv->tls_certificate != NULL; } -void -soup_message_set_soup_request (SoupMessage *msg, - SoupRequest *req) -{ - SoupMessagePrivate *priv = soup_message_get_instance_private (msg); - - priv->request = req; -} - -/** - * soup_message_get_soup_request: - * @msg: a #SoupMessage - * - * If @msg is associated with a #SoupRequest, this returns that - * request. Otherwise it returns %NULL. - * - * Return value: (transfer none): @msg's associated #SoupRequest - * - * Since: 2.42 - */ -SoupRequest * -soup_message_get_soup_request (SoupMessage *msg) -{ - SoupMessagePrivate *priv; - - g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL); - - priv = soup_message_get_instance_private (msg); - return priv->request; -} - /** * SoupMessagePriority: * @SOUP_MESSAGE_PRIORITY_VERY_LOW: The lowest priority, the messages diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h index 01664ab6..e30e9049 100644 --- a/libsoup/soup-message.h +++ b/libsoup/soup-message.h @@ -182,9 +182,6 @@ SOUP_AVAILABLE_IN_2_72 gboolean soup_message_is_feature_disabled (SoupMessage *msg, GType feature_type); -SOUP_AVAILABLE_IN_2_42 -SoupRequest *soup_message_get_soup_request (SoupMessage *msg); - typedef enum { SOUP_MESSAGE_PRIORITY_VERY_LOW = 0, diff --git a/libsoup/soup-request-data.c b/libsoup/soup-request-data.c deleted file mode 100644 index 897ad2a6..00000000 --- a/libsoup/soup-request-data.c +++ /dev/null @@ -1,169 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * soup-request-data.c: data: URI request object - * - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010 Igalia, S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "soup-request-data.h" -#include "soup.h" -#include "soup-misc.h" - -/** - * SECTION:soup-request-data - * @short_description: SoupRequest support for "data" URIs - * - * #SoupRequestData implements #SoupRequest for "data" URIs. - */ - -struct _SoupRequestData { - SoupRequest parent; -}; - -typedef struct { - gsize content_length; - char *content_type; -} SoupRequestDataPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SoupRequestData, soup_request_data, SOUP_TYPE_REQUEST) - -static void -soup_request_data_init (SoupRequestData *data) -{ -} - -static void -soup_request_data_finalize (GObject *object) -{ - SoupRequestData *data = SOUP_REQUEST_DATA (object); - SoupRequestDataPrivate *priv = soup_request_data_get_instance_private (data); - - g_free (priv->content_type); - - G_OBJECT_CLASS (soup_request_data_parent_class)->finalize (object); -} - -static gboolean -soup_request_data_check_uri (SoupRequest *request, - SoupURI *uri, - GError **error) -{ - return uri->host == NULL; -} - -#define BASE64_INDICATOR ";base64" -#define BASE64_INDICATOR_LEN (sizeof (";base64") - 1) - -static GInputStream * -soup_request_data_send (SoupRequest *request, - GCancellable *cancellable, - GError **error) -{ - SoupRequestData *data = SOUP_REQUEST_DATA (request); - SoupRequestDataPrivate *priv = soup_request_data_get_instance_private (data); - SoupURI *uri = soup_request_get_uri (request); - GInputStream *memstream; - const char *comma, *start, *end; - gboolean base64 = FALSE; - char *uristr; - - uristr = soup_uri_to_string (uri, FALSE); - start = uristr + 5; - comma = strchr (start, ','); - if (comma && comma != start) { - /* Deal with MIME type / params */ - if (comma >= start + BASE64_INDICATOR_LEN && !g_ascii_strncasecmp (comma - BASE64_INDICATOR_LEN, BASE64_INDICATOR, BASE64_INDICATOR_LEN)) { - end = comma - BASE64_INDICATOR_LEN; - base64 = TRUE; - } else - end = comma; - - if (end != start) - priv->content_type = soup_uri_decoded_copy (start, end - start, NULL); - } - - memstream = g_memory_input_stream_new (); - - if (comma) - start = comma + 1; - - if (*start) { - int decoded_length = 0; - guchar *buf = (guchar *) soup_uri_decoded_copy (start, strlen (start), - &decoded_length); - - if (base64) - buf = g_base64_decode_inplace ((gchar*) buf, &priv->content_length); - else - priv->content_length = decoded_length; - - g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (memstream), - buf, priv->content_length, - g_free); - } - g_free (uristr); - - return memstream; -} - -static goffset -soup_request_data_get_content_length (SoupRequest *request) -{ - SoupRequestData *data = SOUP_REQUEST_DATA (request); - SoupRequestDataPrivate *priv = soup_request_data_get_instance_private (data); - - return priv->content_length; -} - -static const char * -soup_request_data_get_content_type (SoupRequest *request) -{ - SoupRequestData *data = SOUP_REQUEST_DATA (request); - SoupRequestDataPrivate *priv = soup_request_data_get_instance_private (data); - - if (priv->content_type) - return priv->content_type; - else - return "text/plain;charset=US-ASCII"; -} - -static const char *data_schemes[] = { "data", NULL }; - -static void -soup_request_data_class_init (SoupRequestDataClass *request_data_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (request_data_class); - SoupRequestClass *request_class = - SOUP_REQUEST_CLASS (request_data_class); - - request_class->schemes = data_schemes; - - object_class->finalize = soup_request_data_finalize; - - request_class->check_uri = soup_request_data_check_uri; - request_class->send = soup_request_data_send; - request_class->get_content_length = soup_request_data_get_content_length; - request_class->get_content_type = soup_request_data_get_content_type; -} diff --git a/libsoup/soup-request-data.h b/libsoup/soup-request-data.h deleted file mode 100644 index 27dc1fe5..00000000 --- a/libsoup/soup-request-data.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010 Igalia, S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include "soup-request.h" - -G_BEGIN_DECLS - -#define SOUP_TYPE_REQUEST_DATA (soup_request_data_get_type ()) -SOUP_AVAILABLE_IN_2_34 -G_DECLARE_FINAL_TYPE (SoupRequestData, soup_request_data, SOUP, REQUEST_DATA, SoupRequest) - -G_END_DECLS diff --git a/libsoup/soup-request-file.c b/libsoup/soup-request-file.c deleted file mode 100644 index 740b52a9..00000000 --- a/libsoup/soup-request-file.c +++ /dev/null @@ -1,394 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * soup-request-file.c: file: URI request object - * - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010 Igalia, S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "soup-request-file.h" -#include "soup.h" -#include "soup-directory-input-stream.h" - -/** - * SECTION:soup-request-file - * @short_description: SoupRequest support for "file" and "resource" URIs - * - * #SoupRequestFile implements #SoupRequest for "file" and "resource" - * URIs. - */ - -struct _SoupRequestFile { - SoupRequest parent; -}; - -typedef struct { - GFile *gfile; - - char *mime_type; - goffset size; -} SoupRequestFilePrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SoupRequestFile, soup_request_file, SOUP_TYPE_REQUEST) - -static void -soup_request_file_init (SoupRequestFile *file) -{ - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - - priv->size = -1; -} - -static void -soup_request_file_finalize (GObject *object) -{ - SoupRequestFile *file = SOUP_REQUEST_FILE (object); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - - g_clear_object (&priv->gfile); - g_free (priv->mime_type); - - G_OBJECT_CLASS (soup_request_file_parent_class)->finalize (object); -} - -static gboolean -soup_request_file_check_uri (SoupRequest *request, - SoupURI *uri, - GError **error) -{ - /* "file:/foo" is not valid */ - if (!uri->host) - return FALSE; - - /* but it must be "file:///..." or "file://localhost/..." */ - if (*uri->host && - g_ascii_strcasecmp (uri->host, "localhost") != 0) - return FALSE; - return TRUE; -} - -#ifdef G_OS_WIN32 -static void -windowsify_file_uri_path (char *path) -{ - char *p, *slash; - - /* Copied from g_filename_from_uri(), which we can't use - * directly because it rejects invalid URIs that we need to - * keep. - */ - - /* Turn slashes into backslashes, because that's the canonical spelling */ - p = path; - while ((slash = strchr (p, '/')) != NULL) { - *slash = '\\'; - p = slash + 1; - } - - /* Windows URIs with a drive letter can be like - * "file://host/c:/foo" or "file://host/c|/foo" (some Netscape - * versions). In those cases, start the filename from the - * drive letter. - */ - if (g_ascii_isalpha (path[1])) { - if (path[2] == '|') - path[2] = ':'; - if (path[2] == ':') - memmove (path, path + 1, strlen (path)); - } -} -#endif - -/* Does not do I/O */ -static gboolean -soup_request_file_ensure_file (SoupRequestFile *file, - GCancellable *cancellable, - GError **error) -{ - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - SoupURI *uri; - char *decoded_path; - - if (priv->gfile) - return TRUE; - - uri = soup_request_get_uri (SOUP_REQUEST (file)); - decoded_path = soup_uri_decode (uri->path); - -#ifdef G_OS_WIN32 - windowsify_file_uri_path (decoded_path); -#endif - - if (uri->scheme == SOUP_URI_SCHEME_RESOURCE) { - char *uri_str; - - uri_str = g_strdup_printf ("resource://%s", decoded_path); - priv->gfile = g_file_new_for_uri (uri_str); - g_free (uri_str); - } else - priv->gfile = g_file_new_for_path (decoded_path); - - g_free (decoded_path); - return TRUE; -} - -static GInputStream * -soup_request_file_send (SoupRequest *request, - GCancellable *cancellable, - GError **error) -{ - SoupRequestFile *file = SOUP_REQUEST_FILE (request); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - GInputStream *stream; - GError *my_error = NULL; - - if (!soup_request_file_ensure_file (file, cancellable, error)) - return NULL; - - stream = G_INPUT_STREAM (g_file_read (priv->gfile, - cancellable, &my_error)); - if (stream == NULL) { - if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) { - GFileEnumerator *enumerator; - g_clear_error (&my_error); - enumerator = g_file_enumerate_children (priv->gfile, - "*", - G_FILE_QUERY_INFO_NONE, - cancellable, - error); - if (enumerator) { - stream = soup_directory_input_stream_new (enumerator, - soup_request_get_uri (request)); - g_object_unref (enumerator); - priv->mime_type = g_strdup ("text/html"); - } - } else - g_propagate_error (error, my_error); - } else { - GFileInfo *info = g_file_query_info (priv->gfile, - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," - G_FILE_ATTRIBUTE_STANDARD_SIZE, - 0, cancellable, NULL); - if (info) { - const char *content_type; - priv->size = g_file_info_get_size (info); - content_type = g_file_info_get_content_type (info); - - if (content_type) - priv->mime_type = g_content_type_get_mime_type (content_type); - g_object_unref (info); - } - } - - return stream; -} - -static void -on_enumerate_children_ready (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - GTask *task = G_TASK (user_data); - SoupRequestFile *file = SOUP_REQUEST_FILE (g_task_get_source_object (task)); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - GFileEnumerator *enumerator; - GError *error = NULL; - - enumerator = g_file_enumerate_children_finish (G_FILE (source), result, &error); - if (enumerator == NULL) { - g_task_return_error (task, error); - } else { - GInputStream *stream; - - stream = soup_directory_input_stream_new (enumerator, - soup_request_get_uri (SOUP_REQUEST (file))); - g_object_unref (enumerator); - priv->mime_type = g_strdup ("text/html"); - - g_task_return_pointer (task, stream, g_object_unref); - } - - g_object_unref (task); -} - -static void -on_query_info_ready (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - GTask *task = G_TASK (user_data); - SoupRequestFile *file = SOUP_REQUEST_FILE (g_task_get_source_object (task)); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - GInputStream *stream = G_INPUT_STREAM (g_task_get_task_data (task)); - GFileInfo *info; - GError *error = NULL; - - info = g_file_query_info_finish (G_FILE (source), result, &error); - if (info) { - const char *content_type; - - priv->size = g_file_info_get_size (info); - content_type = g_file_info_get_content_type (info); - - if (content_type) - priv->mime_type = g_content_type_get_mime_type (content_type); - g_object_unref (info); - } - - g_task_return_pointer (task, g_object_ref (stream), g_object_unref); - g_object_unref (task); -} - -static void -on_read_file_ready (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - GTask *task = G_TASK (user_data); - SoupRequestFile *file = SOUP_REQUEST_FILE (g_task_get_source_object (task)); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - GInputStream *stream; - GError *error = NULL; - - stream = G_INPUT_STREAM (g_file_read_finish (G_FILE (source), result, &error)); - if (stream == NULL) { - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) { - g_file_enumerate_children_async (priv->gfile, - "*", - G_FILE_QUERY_INFO_NONE, - G_PRIORITY_DEFAULT, - g_task_get_cancellable (task), - on_enumerate_children_ready, - task); - g_error_free (error); - } else { - g_task_return_error (task, error); - g_object_unref (task); - } - } else { - g_task_set_task_data (task, stream, g_object_unref); - g_file_query_info_async (priv->gfile, - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," - G_FILE_ATTRIBUTE_STANDARD_SIZE, - 0, - G_PRIORITY_DEFAULT, - g_task_get_cancellable (task), - on_query_info_ready, - task); - } -} - -static void -soup_request_file_send_async (SoupRequest *request, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SoupRequestFile *file = SOUP_REQUEST_FILE (request); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - GTask *task; - GError *error = NULL; - - task = g_task_new (request, cancellable, callback, user_data); - - if (!soup_request_file_ensure_file (file, cancellable, &error)) { - g_task_return_error (task, error); - g_object_unref (task); - return; - } - - g_file_read_async (priv->gfile, - G_PRIORITY_DEFAULT, - cancellable, - on_read_file_ready, - task); -} - -static GInputStream * -soup_request_file_send_finish (SoupRequest *request, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (g_task_is_valid (result, request), NULL); - - return g_task_propagate_pointer (G_TASK (result), error); -} - -static goffset -soup_request_file_get_content_length (SoupRequest *request) -{ - SoupRequestFile *file = SOUP_REQUEST_FILE (request); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - return priv->size; -} - -static const char * -soup_request_file_get_content_type (SoupRequest *request) -{ - SoupRequestFile *file = SOUP_REQUEST_FILE (request); - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - - if (!priv->mime_type) - return "application/octet-stream"; - - return priv->mime_type; -} - -static const char *file_schemes[] = { "file", "resource", NULL }; - -static void -soup_request_file_class_init (SoupRequestFileClass *request_file_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (request_file_class); - SoupRequestClass *request_class = - SOUP_REQUEST_CLASS (request_file_class); - - request_class->schemes = file_schemes; - - object_class->finalize = soup_request_file_finalize; - - request_class->check_uri = soup_request_file_check_uri; - request_class->send = soup_request_file_send; - request_class->send_async = soup_request_file_send_async; - request_class->send_finish = soup_request_file_send_finish; - request_class->get_content_length = soup_request_file_get_content_length; - request_class->get_content_type = soup_request_file_get_content_type; -} - -/** - * soup_request_file_get_file: - * @file: a #SoupRequestFile - * - * Gets a #GFile corresponding to @file's URI - * - * Return value: (transfer full): a #GFile corresponding to @file - * - * Since: 2.40 - */ -GFile * -soup_request_file_get_file (SoupRequestFile *file) -{ - SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file); - return g_object_ref (priv->gfile); -} diff --git a/libsoup/soup-request-file.h b/libsoup/soup-request-file.h deleted file mode 100644 index 02688224..00000000 --- a/libsoup/soup-request-file.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010 Igalia, S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include "soup-request.h" - -G_BEGIN_DECLS - -#define SOUP_TYPE_REQUEST_FILE (soup_request_file_get_type ()) -SOUP_AVAILABLE_IN_2_34 -G_DECLARE_FINAL_TYPE (SoupRequestFile, soup_request_file, SOUP, REQUEST_FILE, SoupRequest) - -SOUP_AVAILABLE_IN_2_34 -GFile *soup_request_file_get_file (SoupRequestFile *file); - -G_END_DECLS diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c deleted file mode 100644 index 5dbfe0e9..00000000 --- a/libsoup/soup-request-http.c +++ /dev/null @@ -1,243 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * soup-request-http.c: http: URI request object - * - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010 Igalia, S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "soup-request-http.h" -#include "soup.h" -#include "soup-message-private.h" -#include "soup-session-private.h" - -/** - * SECTION:soup-request-http - * @short_description: SoupRequest support for "http" and "https" URIs - * - * #SoupRequestHTTP implements #SoupRequest for "http" and "https" - * URIs. - * - * To do more complicated HTTP operations using the #SoupRequest APIs, - * call soup_request_http_get_message() to get the request's - * #SoupMessage. - */ - -struct _SoupRequestHTTP { - SoupRequest parent; -}; - -typedef struct { - SoupMessage *msg; - char *content_type; -} SoupRequestHTTPPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SoupRequestHTTP, soup_request_http, SOUP_TYPE_REQUEST) - -static void content_sniffed (SoupMessage *msg, - const char *content_type, - GHashTable *params, - gpointer user_data); - -static void -soup_request_http_init (SoupRequestHTTP *http) -{ -} - -static gboolean -soup_request_http_check_uri (SoupRequest *request, - SoupURI *uri, - GError **error) -{ - SoupRequestHTTP *http = SOUP_REQUEST_HTTP (request); - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - - if (!SOUP_URI_VALID_FOR_HTTP (uri)) - return FALSE; - - priv->msg = soup_message_new_from_uri (SOUP_METHOD_GET, uri); - soup_message_set_soup_request (priv->msg, request); - - g_signal_connect (priv->msg, "content-sniffed", - G_CALLBACK (content_sniffed), http); - return TRUE; -} - -static void -soup_request_http_finalize (GObject *object) -{ - SoupRequestHTTP *http = SOUP_REQUEST_HTTP (object); - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - - if (priv->msg) { - g_signal_handlers_disconnect_by_func (priv->msg, - G_CALLBACK (content_sniffed), - http); - g_object_unref (priv->msg); - } - - g_free (priv->content_type); - - G_OBJECT_CLASS (soup_request_http_parent_class)->finalize (object); -} - -static GInputStream * -soup_request_http_send (SoupRequest *request, - GCancellable *cancellable, - GError **error) -{ - SoupRequestHTTP *http = SOUP_REQUEST_HTTP (request); - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - SoupSession *session = soup_request_get_session (request); - - return soup_session_send (session, priv->msg, - cancellable, error); -} - - -static void -http_input_stream_ready_cb (GObject *source, GAsyncResult *result, gpointer user_data) -{ - GTask *task = user_data; - GError *error = NULL; - GInputStream *stream; - - stream = soup_session_send_finish (SOUP_SESSION (source), 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 -soup_request_http_send_async (SoupRequest *request, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SoupRequestHTTP *http = SOUP_REQUEST_HTTP (request); - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - SoupSession *session = soup_request_get_session (request); - GTask *task; - - task = g_task_new (request, cancellable, callback, user_data); - soup_session_send_async (session, priv->msg, - G_PRIORITY_DEFAULT, - cancellable, - http_input_stream_ready_cb, task); -} - -static GInputStream * -soup_request_http_send_finish (SoupRequest *request, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (g_task_is_valid (result, request), NULL); - - return g_task_propagate_pointer (G_TASK (result), error); -} - -static goffset -soup_request_http_get_content_length (SoupRequest *request) -{ - SoupRequestHTTP *http = SOUP_REQUEST_HTTP (request); - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - - return soup_message_headers_get_content_length (priv->msg->response_headers); -} - -static void -content_sniffed (SoupMessage *msg, - const char *content_type, - GHashTable *params, - gpointer user_data) -{ - SoupRequestHTTP *http = user_data; - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - GString *sniffed_type; - - sniffed_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 (sniffed_type, "; "); - soup_header_g_string_append_param (sniffed_type, key, value); - } - } - g_free (priv->content_type); - priv->content_type = g_string_free (sniffed_type, FALSE); -} - -static const char * -soup_request_http_get_content_type (SoupRequest *request) -{ - SoupRequestHTTP *http = SOUP_REQUEST_HTTP (request); - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - - return priv->content_type; -} - -static const char *http_schemes[] = { "http", "https", NULL }; - -static void -soup_request_http_class_init (SoupRequestHTTPClass *request_http_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (request_http_class); - SoupRequestClass *request_class = - SOUP_REQUEST_CLASS (request_http_class); - - request_class->schemes = http_schemes; - - object_class->finalize = soup_request_http_finalize; - - request_class->check_uri = soup_request_http_check_uri; - request_class->send = soup_request_http_send; - request_class->send_async = soup_request_http_send_async; - request_class->send_finish = soup_request_http_send_finish; - request_class->get_content_length = soup_request_http_get_content_length; - request_class->get_content_type = soup_request_http_get_content_type; -} - -/** - * soup_request_http_get_message: - * @http: a #SoupRequestHTTP object - * - * Gets a new reference to the #SoupMessage associated to this SoupRequest - * - * Returns: (transfer full): a new reference to the #SoupMessage - * - * Since: 2.40 - */ -SoupMessage * -soup_request_http_get_message (SoupRequestHTTP *http) -{ - g_return_val_if_fail (SOUP_IS_REQUEST_HTTP (http), NULL); - SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http); - - return g_object_ref (priv->msg); -} diff --git a/libsoup/soup-request-http.h b/libsoup/soup-request-http.h deleted file mode 100644 index c61c496e..00000000 --- a/libsoup/soup-request-http.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010 Igalia, S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include "soup-request.h" - -G_BEGIN_DECLS - -#define SOUP_TYPE_REQUEST_HTTP (soup_request_http_get_type ()) -SOUP_AVAILABLE_IN_2_34 -G_DECLARE_FINAL_TYPE (SoupRequestHTTP, soup_request_http, SOUP, REQUEST_HTTP, SoupRequest) - -SOUP_AVAILABLE_IN_2_34 -SoupMessage *soup_request_http_get_message (SoupRequestHTTP *http); - -G_END_DECLS diff --git a/libsoup/soup-request.c b/libsoup/soup-request.c deleted file mode 100644 index 6a1f53ba..00000000 --- a/libsoup/soup-request.c +++ /dev/null @@ -1,404 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * soup-request.c: Protocol-independent streaming request interface - * - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010, Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "soup-request.h" -#include "soup.h" - -/** - * SECTION:soup-request - * @short_description: Protocol-independent streaming request interface - * - * A #SoupRequest is created by #SoupSession, and represents a request - * to retrieve a particular URI. - */ - -/** - * SoupRequest: - * - * A request to retrieve a particular URI. - * - * Since: 2.42 - */ - -enum { - PROP_0, - PROP_URI, - PROP_SESSION -}; - -typedef struct { - SoupURI *uri; - SoupSession *session; -} SoupRequestPrivate; - -static void soup_request_initable_interface_init (GInitableIface *initable_interface); - -G_DEFINE_TYPE_WITH_CODE (SoupRequest, soup_request, G_TYPE_OBJECT, - G_ADD_PRIVATE (SoupRequest) - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, - soup_request_initable_interface_init)) - -static void -soup_request_init (SoupRequest *request) -{ -} - -static void -soup_request_finalize (GObject *object) -{ - SoupRequest *request = SOUP_REQUEST (object); - SoupRequestPrivate *priv = soup_request_get_instance_private (request); - - g_clear_pointer (&priv->uri, soup_uri_free); - g_clear_object (&priv->session); - - G_OBJECT_CLASS (soup_request_parent_class)->finalize (object); -} - -static void -soup_request_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SoupRequest *request = SOUP_REQUEST (object); - SoupRequestPrivate *priv = soup_request_get_instance_private (request); - - switch (prop_id) { - case PROP_URI: - if (priv->uri) - soup_uri_free (priv->uri); - priv->uri = g_value_dup_boxed (value); - break; - case PROP_SESSION: - if (priv->session) - g_object_unref (priv->session); - priv->session = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -soup_request_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SoupRequest *request = SOUP_REQUEST (object); - SoupRequestPrivate *priv = soup_request_get_instance_private (request); - - switch (prop_id) { - case PROP_URI: - g_value_set_boxed (value, priv->uri); - break; - case PROP_SESSION: - g_value_set_object (value, priv->session); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static gboolean -soup_request_initable_init (GInitable *initable, - GCancellable *cancellable, - GError **error) -{ - SoupRequest *request = SOUP_REQUEST (initable); - SoupRequestPrivate *priv = soup_request_get_instance_private (request); - gboolean ok; - - if (!priv->uri) { - g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, - _("No URI provided")); - return FALSE; - } - - ok = SOUP_REQUEST_GET_CLASS (initable)-> - check_uri (request, priv->uri, error); - - if (!ok && error && !*error) { - char *uri_string = soup_uri_to_string (priv->uri, FALSE); - g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, - _("Invalid “%s” URI: %s"), - priv->uri->scheme, - uri_string); - g_free (uri_string); - } - - return ok; -} - -static gboolean -soup_request_default_check_uri (SoupRequest *request, - SoupURI *uri, - GError **error) -{ - return TRUE; -} - -/* Default implementation: assume the sync implementation doesn't block */ -static void -soup_request_default_send_async (SoupRequest *request, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - 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 * -soup_request_default_send_finish (SoupRequest *request, - GAsyncResult *result, - GError **error) -{ - return g_task_propagate_pointer (G_TASK (result), error); -} - -/** - * soup_request_send: - * @request: a #SoupRequest - * @cancellable: a #GCancellable or %NULL - * @error: return location for a #GError, or %NULL - * - * Synchronously requests the URI pointed to by @request, and returns - * a #GInputStream that can be used to read its contents. - * - * Return value: (transfer full): a #GInputStream that can be used to - * read from the URI pointed to by @request. - * - * Since: 2.42 - */ -GInputStream * -soup_request_send (SoupRequest *request, - GCancellable *cancellable, - GError **error) -{ - return SOUP_REQUEST_GET_CLASS (request)-> - send (request, cancellable, error); -} - -/** - * soup_request_send_async: - * @request: a #SoupRequest - * @cancellable: a #GCancellable or %NULL - * @callback: a #GAsyncReadyCallback - * @user_data: user data passed to @callback - * - * Begins an asynchronously request for the URI pointed to by - * @request. - * - * Since: 2.42 - */ -void -soup_request_send_async (SoupRequest *request, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SOUP_REQUEST_GET_CLASS (request)-> - send_async (request, cancellable, callback, user_data); -} - -/** - * soup_request_send_finish: - * @request: a #SoupRequest - * @result: the #GAsyncResult - * @error: return location for a #GError, or %NULL - * - * Gets the result of a soup_request_send_async(). - * - * Return value: (transfer full): a #GInputStream that can be used to - * read from the URI pointed to by @request. - * - * Since: 2.42 - */ -GInputStream * -soup_request_send_finish (SoupRequest *request, - GAsyncResult *result, - GError **error) -{ - return SOUP_REQUEST_GET_CLASS (request)-> - send_finish (request, result, error); -} - -static void -soup_request_class_init (SoupRequestClass *request_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (request_class); - - request_class->check_uri = soup_request_default_check_uri; - request_class->send_async = soup_request_default_send_async; - request_class->send_finish = soup_request_default_send_finish; - - object_class->finalize = soup_request_finalize; - 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, - "URI", - "The request URI", - SOUP_TYPE_URI, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - /** - * 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, - "Session", - "The request's session", - SOUP_TYPE_SESSION, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); -} - -static void -soup_request_initable_interface_init (GInitableIface *initable_interface) -{ - initable_interface->init = soup_request_initable_init; -} - -/** - * soup_request_get_uri: - * @request: a #SoupRequest - * - * Gets @request's URI - * - * Return value: (transfer none): @request's URI - * - * Since: 2.42 - */ -SoupURI * -soup_request_get_uri (SoupRequest *request) -{ - SoupRequestPrivate *priv = soup_request_get_instance_private (request); - return priv->uri; -} - -/** - * soup_request_get_session: - * @request: a #SoupRequest - * - * Gets @request's #SoupSession - * - * Return value: (transfer none): @request's #SoupSession - * - * Since: 2.42 - */ -SoupSession * -soup_request_get_session (SoupRequest *request) -{ - SoupRequestPrivate *priv = soup_request_get_instance_private (request); - return priv->session; -} - -/** - * soup_request_get_content_length: - * @request: a #SoupRequest - * - * 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.42 - */ -goffset -soup_request_get_content_length (SoupRequest *request) -{ - return SOUP_REQUEST_GET_CLASS (request)->get_content_length (request); -} - -/** - * soup_request_get_content_type: - * @request: a #SoupRequest - * - * 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: (nullable): the type of the data represented by - * @request, or %NULL if not known. - * - * Since: 2.42 - */ -const char * -soup_request_get_content_type (SoupRequest *request) -{ - return SOUP_REQUEST_GET_CLASS (request)->get_content_type (request); -} diff --git a/libsoup/soup-request.h b/libsoup/soup-request.h deleted file mode 100644 index fbb6b22a..00000000 --- a/libsoup/soup-request.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2009, 2010 Red Hat, Inc. - * Copyright (C) 2010 Igalia, S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include - -#include "soup-types.h" - -G_BEGIN_DECLS - -#define SOUP_TYPE_REQUEST (soup_request_get_type ()) -SOUP_AVAILABLE_IN_2_34 -G_DECLARE_DERIVABLE_TYPE (SoupRequest, soup_request, SOUP, REQUEST, GObject) - -struct _SoupRequestClass { - GObjectClass parent; - - const char **schemes; - - gboolean (*check_uri) (SoupRequest *req_base, - SoupURI *uri, - GError **error); - - GInputStream * (*send) (SoupRequest *request, - GCancellable *cancellable, - GError **error); - void (*send_async) (SoupRequest *request, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - GInputStream * (*send_finish) (SoupRequest *request, - GAsyncResult *result, - GError **error); - - goffset (*get_content_length) (SoupRequest *request); - const char * (*get_content_type) (SoupRequest *request); -}; - -#define SOUP_REQUEST_URI "uri" -#define SOUP_REQUEST_SESSION "session" - -SOUP_AVAILABLE_IN_2_34 -GInputStream *soup_request_send (SoupRequest *request, - GCancellable *cancellable, - GError **error); -SOUP_AVAILABLE_IN_2_34 -void soup_request_send_async (SoupRequest *request, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -SOUP_AVAILABLE_IN_2_34 -GInputStream *soup_request_send_finish (SoupRequest *request, - GAsyncResult *result, - GError **error); - -SOUP_AVAILABLE_IN_2_34 -SoupURI *soup_request_get_uri (SoupRequest *request); -SOUP_AVAILABLE_IN_2_34 -SoupSession *soup_request_get_session (SoupRequest *request); - -SOUP_AVAILABLE_IN_2_34 -goffset soup_request_get_content_length (SoupRequest *request); -SOUP_AVAILABLE_IN_2_34 -const char *soup_request_get_content_type (SoupRequest *request); - -G_END_DECLS diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c index d3c82811..57e74e2e 100644 --- a/libsoup/soup-session.c +++ b/libsoup/soup-session.c @@ -56,15 +56,12 @@ * logging HTTP traffic, #SoupContentDecoder provides support for * compressed response handling, and #SoupContentSniffer provides * support for HTML5-style response body content sniffing. - * Additionally, subtypes of #SoupAuth and #SoupRequest can be added - * as features, to add support for additional authentication and URI - * types. + * Additionally, subtypes of #SoupAuth can be added + * as features, to add support for additional authentication types. * * All #SoupSessions are created with a #SoupAuthManager, and support - * for %SOUP_TYPE_AUTH_BASIC and %SOUP_TYPE_AUTH_DIGEST. For - * #SoupRequest types, #SoupRequestHTTP, #SoupRequestFile, and - * #SoupRequestData are supported. Additionally, sessions using the - * plain #SoupSession class (rather than one of its deprecated + * for %SOUP_TYPE_AUTH_BASIC and %SOUP_TYPE_AUTH_DIGEST. Additionally, + * sessions using the plain #SoupSession class (rather than one of its deprecated * subtypes) have a #SoupContentDecoder by default. **/ @@ -133,8 +130,6 @@ typedef struct { GMainContext *async_context; char **http_aliases, **https_aliases; - - GHashTable *request_types; } SoupSessionPrivate; #define SOUP_IS_PLAIN_SESSION(o) (G_TYPE_FROM_INSTANCE (o) == SOUP_TYPE_SESSION) @@ -288,12 +283,6 @@ soup_session_init (SoupSession *session) */ priv->proxy_use_default = TRUE; priv->tlsdb_use_default = TRUE; - - priv->request_types = g_hash_table_new (soup_str_case_hash, - soup_str_case_equal); - soup_session_add_feature_by_type (session, SOUP_TYPE_REQUEST_HTTP); - soup_session_add_feature_by_type (session, SOUP_TYPE_REQUEST_FILE); - soup_session_add_feature_by_type (session, SOUP_TYPE_REQUEST_DATA); } static void @@ -344,8 +333,6 @@ soup_session_finalize (GObject *object) g_free (priv->http_aliases); g_free (priv->https_aliases); - g_hash_table_destroy (priv->request_types); - g_clear_pointer (&priv->socket_props, soup_socket_properties_unref); G_OBJECT_CLASS (soup_session_parent_class)->finalize (object); @@ -2179,8 +2166,7 @@ soup_session_add_feature (SoupSession *session, SoupSessionFeature *feature) * * If @feature_type is not a #SoupSessionFeature type, this gives each * existing feature on @session the chance to accept @feature_type as - * a "subfeature". This can be used to add new #SoupAuth or - * #SoupRequest types, for instance. + * a "subfeature". This can be used to add new #SoupAuth types, for instance. * * You can also add a feature to the session at construct time by * using the %SOUP_SESSION_ADD_FEATURE_BY_TYPE property. @@ -2205,16 +2191,6 @@ soup_session_add_feature_by_type (SoupSession *session, GType feature_type) feature = g_object_new (feature_type, NULL); soup_session_add_feature (session, feature); g_object_unref (feature); - } else if (g_type_is_a (feature_type, SOUP_TYPE_REQUEST)) { - SoupRequestClass *request_class; - int i; - - request_class = g_type_class_ref (feature_type); - for (i = 0; request_class->schemes[i]; i++) { - g_hash_table_insert (priv->request_types, - (char *)request_class->schemes[i], - GSIZE_TO_POINTER (feature_type)); - } } else { GSList *f; @@ -2281,17 +2257,6 @@ soup_session_remove_feature_by_type (SoupSession *session, GType feature_type) goto restart; } } - } else if (g_type_is_a (feature_type, SOUP_TYPE_REQUEST)) { - SoupRequestClass *request_class; - int i; - - request_class = g_type_class_peek (feature_type); - if (!request_class) - return; - for (i = 0; request_class->schemes[i]; i++) { - g_hash_table_remove (priv->request_types, - request_class->schemes[i]); - } } else { for (f = priv->features; f; f = f->next) { if (soup_session_feature_remove_feature (f->data, feature_type)) @@ -2308,8 +2273,7 @@ soup_session_remove_feature_by_type (SoupSession *session, GType feature_type) * * Tests if @session has at a feature of type @feature_type (which can * be the type of either a #SoupSessionFeature, or else a subtype of - * some class managed by another feature, such as #SoupAuth or - * #SoupRequest). + * some class managed by another feature, such as #SoupAuth). * * Return value: %TRUE or %FALSE * @@ -2331,22 +2295,6 @@ soup_session_has_feature (SoupSession *session, if (G_TYPE_CHECK_INSTANCE_TYPE (f->data, feature_type)) return TRUE; } - } else if (g_type_is_a (feature_type, SOUP_TYPE_REQUEST)) { - SoupRequestClass *request_class; - int i; - - request_class = g_type_class_peek (feature_type); - if (!request_class) - return FALSE; - - for (i = 0; request_class->schemes[i]; i++) { - gpointer type; - - type = g_hash_table_lookup (priv->request_types, - request_class->schemes[i]); - if (type && g_type_is_a (GPOINTER_TO_SIZE (type), feature_type)) - return TRUE; - } } else { for (f = priv->features; f; f = f->next) { if (soup_session_feature_has_feature (f->data, feature_type)) @@ -4690,197 +4638,6 @@ soup_session_get_bytes (SoupSession *session, return bytes; } -/** - * soup_session_request: - * @session: a #SoupSession - * @uri_string: a URI, in string form - * @error: return location for a #GError, or %NULL - * - * Creates a #SoupRequest for retrieving @uri_string. - * - * Return value: (transfer full): a new #SoupRequest, or - * %NULL on error. - * - * Since: 2.42 - */ -SoupRequest * -soup_session_request (SoupSession *session, const char *uri_string, - GError **error) -{ - SoupURI *uri; - SoupRequest *req; - - uri = soup_uri_new (uri_string); - if (!uri) { - g_set_error (error, SOUP_REQUEST_ERROR, - SOUP_REQUEST_ERROR_BAD_URI, - _("Could not parse URI “%s”"), uri_string); - return NULL; - } - - req = soup_session_request_uri (session, uri, error); - soup_uri_free (uri); - return req; -} - -/** - * soup_session_request_uri: - * @session: a #SoupSession - * @uri: a #SoupURI representing the URI to retrieve - * @error: return location for a #GError, or %NULL - * - * Creates a #SoupRequest for retrieving @uri. - * - * Return value: (transfer full): a new #SoupRequest, or - * %NULL on error. - * - * Since: 2.42 - */ -SoupRequest * -soup_session_request_uri (SoupSession *session, SoupURI *uri, - GError **error) -{ - SoupSessionPrivate *priv; - GType request_type; - - g_return_val_if_fail (SOUP_IS_SESSION (session), NULL); - - priv = soup_session_get_instance_private (session); - - request_type = (GType)GPOINTER_TO_SIZE (g_hash_table_lookup (priv->request_types, uri->scheme)); - if (!request_type) { - g_set_error (error, SOUP_REQUEST_ERROR, - SOUP_REQUEST_ERROR_UNSUPPORTED_URI_SCHEME, - _("Unsupported URI scheme “%s”"), uri->scheme); - return NULL; - } - - return g_initable_new (request_type, NULL, error, - "uri", uri, - "session", session, - NULL); -} - -static SoupRequestHTTP * -initialize_http_request (SoupRequest *req, - const char *method, - GError **error) -{ - SoupRequestHTTP *http; - SoupMessage *msg; - - if (!SOUP_IS_REQUEST_HTTP (req)) { - g_object_unref (req); - g_set_error (error, SOUP_REQUEST_ERROR, - SOUP_REQUEST_ERROR_BAD_URI, - _("Not an HTTP URI")); - return NULL; - } - - http = SOUP_REQUEST_HTTP (req); - msg = soup_request_http_get_message (http); - g_object_set (G_OBJECT (msg), - SOUP_MESSAGE_METHOD, method, - NULL); - g_object_unref (msg); - - return http; -} - -/** - * soup_session_request_http: - * @session: a #SoupSession - * @method: an HTTP method - * @uri_string: a URI, in string form - * @error: return location for a #GError, or %NULL - * - * Creates a #SoupRequest for retrieving @uri_string, which must be an - * "http" or "https" URI (or another protocol listed in @session's - * #SoupSession:http-aliases or #SoupSession:https-aliases). - * - * Return value: (transfer full): a new #SoupRequestHTTP, or - * %NULL on error. - * - * Since: 2.42 - */ -SoupRequestHTTP * -soup_session_request_http (SoupSession *session, - const char *method, - const char *uri_string, - GError **error) -{ - SoupRequest *req; - - req = soup_session_request (session, uri_string, error); - if (!req) - return NULL; - - return initialize_http_request (req, method, error); -} - -/** - * soup_session_request_http_uri: - * @session: a #SoupSession - * @method: an HTTP method - * @uri: a #SoupURI representing the URI to retrieve - * @error: return location for a #GError, or %NULL - * - * Creates a #SoupRequest for retrieving @uri, which must be an - * "http" or "https" URI (or another protocol listed in @session's - * #SoupSession:http-aliases or #SoupSession:https-aliases). - * - * Return value: (transfer full): a new #SoupRequestHTTP, or - * %NULL on error. - * - * Since: 2.42 - */ -SoupRequestHTTP * -soup_session_request_http_uri (SoupSession *session, - const char *method, - SoupURI *uri, - GError **error) -{ - SoupRequest *req; - - req = soup_session_request_uri (session, uri, error); - if (!req) - return NULL; - - return initialize_http_request (req, method, error); -} - -/** - * SOUP_REQUEST_ERROR: - * - * A #GError domain for #SoupRequest-related errors. Used with - * #SoupRequestError. - * - * Since: 2.42 - */ -/** - * SoupRequestError: - * @SOUP_REQUEST_ERROR_BAD_URI: the URI could not be parsed - * @SOUP_REQUEST_ERROR_UNSUPPORTED_URI_SCHEME: the URI scheme is not - * supported by this #SoupSession - * @SOUP_REQUEST_ERROR_PARSING: the server's response could not - * be parsed - * @SOUP_REQUEST_ERROR_ENCODING: the server's response was in an - * unsupported format - * - * A #SoupRequest error. - * - * Since: 2.42 - */ - -GQuark -soup_request_error_quark (void) -{ - static GQuark error; - if (!error) - error = g_quark_from_static_string ("soup_request_error_quark"); - return error; -} - static GIOStream * steal_connection (SoupSession *session, SoupMessageQueueItem *item) diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h index 9a5a5521..09597f24 100644 --- a/libsoup/soup-session.h +++ b/libsoup/soup-session.h @@ -160,36 +160,6 @@ GBytes *soup_session_get_bytes_finish (SoupSession *ses char **content_type, GError **error); -SOUP_AVAILABLE_IN_2_42 -SoupRequest *soup_session_request (SoupSession *session, - const char *uri_string, - GError **error); -SOUP_AVAILABLE_IN_2_42 -SoupRequest *soup_session_request_uri (SoupSession *session, - SoupURI *uri, - GError **error); -SOUP_AVAILABLE_IN_2_42 -SoupRequestHTTP *soup_session_request_http (SoupSession *session, - const char *method, - const char *uri_string, - GError **error); -SOUP_AVAILABLE_IN_2_42 -SoupRequestHTTP *soup_session_request_http_uri (SoupSession *session, - const char *method, - SoupURI *uri, - GError **error); - -SOUP_AVAILABLE_IN_2_42 -GQuark soup_request_error_quark (void); -#define SOUP_REQUEST_ERROR soup_request_error_quark () - -typedef enum { - SOUP_REQUEST_ERROR_BAD_URI, - SOUP_REQUEST_ERROR_UNSUPPORTED_URI_SCHEME, - SOUP_REQUEST_ERROR_PARSING, - SOUP_REQUEST_ERROR_ENCODING -} SoupRequestError; - SOUP_AVAILABLE_IN_2_50 void soup_session_websocket_connect_async (SoupSession *session, SoupMessage *msg, diff --git a/libsoup/soup.h b/libsoup/soup.h index bd95488e..c2b6c60b 100644 --- a/libsoup/soup.h +++ b/libsoup/soup.h @@ -37,10 +37,6 @@ extern "C" { #include "soup-method.h" #include "soup-multipart.h" #include "soup-multipart-input-stream.h" -#include "soup-request.h" -#include "soup-request-data.h" -#include "soup-request-file.h" -#include "soup-request-http.h" #include "server/soup-auth-domain.h" #include "server/soup-auth-domain-basic.h" #include "server/soup-auth-domain-digest.h" diff --git a/tests/meson.build b/tests/meson.build index b01397cd..1adeb167 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -51,7 +51,6 @@ tests = [ ['ntlm', true, []], ['redirect', true, []], ['request-body', true, []], - ['resource', true, []], ['samesite', true, []], ['session', true, []], ['server-auth', true, []], diff --git a/tests/resource-test.c b/tests/resource-test.c deleted file mode 100644 index 10cfb92a..00000000 --- a/tests/resource-test.c +++ /dev/null @@ -1,221 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2012 Igalia S.L. - */ - -#include "test-utils.h" - -GBytes *index_buffer; - -typedef struct { - GString *body; - char buffer[1024]; - GMainLoop *loop; -} AsyncRequestData; - -static void -stream_closed (GObject *source, GAsyncResult *result, gpointer user_data) -{ - GInputStream *in = G_INPUT_STREAM (source); - AsyncRequestData *data = user_data; - GError *error = NULL; - - g_input_stream_close_finish (in, result, &error); - g_assert_no_error (error); - g_main_loop_quit (data->loop); - g_object_unref (in); -} - -static void -test_read_ready (GObject *source, GAsyncResult *result, gpointer user_data) -{ - GInputStream *in = G_INPUT_STREAM (source); - AsyncRequestData *data = user_data; - gssize nread; - GError *error = NULL; - - nread = g_input_stream_read_finish (in, result, &error); - if (nread == -1) { - g_assert_no_error (error); - g_clear_error (&error); - g_input_stream_close (in, NULL, NULL); - g_object_unref (in); - return; - } else if (nread == 0) { - g_input_stream_close_async (in, G_PRIORITY_DEFAULT, NULL, - stream_closed, data); - return; - } - - g_string_append_len (data->body, data->buffer, nread); - g_input_stream_read_async (in, data->buffer, sizeof (data->buffer), - G_PRIORITY_DEFAULT, NULL, - test_read_ready, data); -} - -static void -async_request_sent (GObject *source, GAsyncResult *result, gpointer user_data) -{ - GInputStream *in; - AsyncRequestData *data = user_data; - GError *error = NULL; - - in = soup_request_send_finish (SOUP_REQUEST (source), result, &error); - if (!in) { - g_assert_no_error (error); - g_clear_error (&error); - return; - } - - g_input_stream_read_async (in, data->buffer, sizeof (data->buffer), - G_PRIORITY_DEFAULT, NULL, - test_read_ready, data); -} - -static void -do_async_request (SoupRequest *request) -{ - AsyncRequestData data; - - data.body = g_string_new (NULL); - soup_request_send_async (request, NULL, async_request_sent, &data); - - data.loop = g_main_loop_new (g_main_context_get_thread_default (), TRUE); - g_main_loop_run (data.loop); - g_main_loop_unref (data.loop); - - soup_assert_cmpmem (data.body->str, data.body->len, - g_bytes_get_data (index_buffer, NULL), - g_bytes_get_size (index_buffer)); - g_string_free (data.body, TRUE); -} - -static void -do_sync_request (SoupRequest *request) -{ - GInputStream *in; - GString *body; - char buffer[1024]; - gssize nread; - GError *error = NULL; - - in = soup_request_send (request, NULL, &error); - if (!in) { - g_assert_no_error (error); - g_clear_error (&error); - return; - } - - body = g_string_new (NULL); - do { - nread = g_input_stream_read (in, buffer, sizeof (buffer), - NULL, &error); - if (nread == -1) { - g_assert_no_error (error); - g_clear_error (&error); - break; - } - g_string_append_len (body, buffer, nread); - } while (nread > 0); - - g_input_stream_close (in, NULL, &error); - g_assert_no_error (error); - g_clear_error (&error); - g_object_unref (in); - - soup_assert_cmpmem (body->str, body->len, g_bytes_get_data (index_buffer, NULL), g_bytes_get_size (index_buffer)); - g_string_free (body, TRUE); -} - - -static void -do_request (const char *uri_string, gconstpointer sync) -{ - SoupSession *session; - SoupRequest *request; - GError *error = NULL; - - session = soup_test_session_new (SOUP_TYPE_SESSION, - NULL); - - request = soup_session_request (session, uri_string, &error); - g_assert_no_error (error); - - if (GPOINTER_TO_UINT (sync)) - do_sync_request (request); - else - do_async_request (request); - - g_object_unref (request); - soup_test_session_abort_unref (session); -} - -static void -do_request_file_test (gconstpointer sync) -{ - GFile *index; - char *uri_string; - - index = g_file_new_for_path (g_test_get_filename (G_TEST_DIST, "index.txt", NULL)); - uri_string = g_file_get_uri (index); - g_object_unref (index); - - do_request (uri_string, sync); - g_free (uri_string); -} - -static void -do_request_data_test (gconstpointer sync) -{ - gchar *base64; - char *uri_string; - - base64 = g_base64_encode ((const guchar *)g_bytes_get_data (index_buffer, NULL), g_bytes_get_size (index_buffer)); - uri_string = g_strdup_printf ("data:text/plain;charset=utf8;base64,%s", base64); - g_free (base64); - - do_request (uri_string, sync); - g_free (uri_string); -} - -static void -do_request_gresource_test (gconstpointer sync) -{ - do_request ("resource:///org/gnome/libsoup/tests/index.txt", sync); -} - -int -main (int argc, char **argv) -{ - int ret; - - test_init (argc, argv, NULL); - - index_buffer = soup_test_get_index (); - soup_test_register_resources (); - - g_test_add_data_func ("/resource/sync/file", - GUINT_TO_POINTER (TRUE), - do_request_file_test); - g_test_add_data_func ("/resource/sync/data", - GUINT_TO_POINTER (TRUE), - do_request_data_test); - g_test_add_data_func ("/resource/sync/gresource", - GUINT_TO_POINTER (TRUE), - do_request_gresource_test); - - g_test_add_data_func ("/resource/async/file", - GUINT_TO_POINTER (FALSE), - do_request_file_test); - g_test_add_data_func ("/resource/async/data", - GUINT_TO_POINTER (FALSE), - do_request_data_test); - g_test_add_data_func ("/resource/async/gresource", - GUINT_TO_POINTER (FALSE), - do_request_gresource_test); - - ret = g_test_run (); - - test_cleanup (); - return ret; -} diff --git a/tests/session-test.c b/tests/session-test.c index 1417c62e..fac0d5b9 100644 --- a/tests/session-test.c +++ b/tests/session-test.c @@ -364,15 +364,6 @@ do_features_test (void) g_assert_null (soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER)); g_slist_free (features); - /* HTTP, File and Data requests are always added */ - g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_HTTP)); - g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_FILE)); - g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_DATA)); - soup_session_remove_feature_by_type (session, SOUP_TYPE_REQUEST_FILE); - g_assert_false (soup_session_has_feature (session, SOUP_TYPE_REQUEST_FILE)); - g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_HTTP)); - g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_DATA)); - soup_test_session_abort_unref (session); } -- cgit v1.2.1