[libsoup/carlosgc/message-props: 2/2] message: rename options-ping property as is-options-ping
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/message-props: 2/2] message: rename options-ping property as is-options-ping
- Date: Mon, 29 Mar 2021 12:56:27 +0000 (UTC)
commit bed823d1249a7eb7884c5d03ebceecbf9f1c099a
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Mar 29 14:55:22 2021 +0200
message: rename options-ping property as is-options-ping
And add public getter, setter and constructor.
docs/reference/libsoup-3.0-sections.txt | 4 ++
libsoup/soup-message-io.c | 2 +-
libsoup/soup-message-private.h | 2 -
libsoup/soup-message.c | 99 +++++++++++++++++++++++++++------
libsoup/soup-message.h | 10 ++++
tests/server-test.c | 16 ++----
6 files changed, 102 insertions(+), 31 deletions(-)
---
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt
index c15bda3d..77e03b56 100644
--- a/docs/reference/libsoup-3.0-sections.txt
+++ b/docs/reference/libsoup-3.0-sections.txt
@@ -11,6 +11,10 @@ soup_message_new_from_multipart
soup_message_set_request_body
soup_message_set_request_body_from_bytes
<SUBSECTION>
+soup_message_new_options_ping
+soup_message_get_is_options_ping
+soup_message_set_is_options_ping
+<SUBSECTION>
SoupHTTPVersion
soup_message_get_http_version
soup_message_get_uri
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index b7fd834e..8aef3170 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -279,7 +279,7 @@ write_headers (SoupMessage *msg,
*/
if (proxy)
uri_string = g_uri_to_string (uri);
- else if (soup_message_is_options_ping (msg))
+ else if (soup_message_get_is_options_ping (msg))
uri_string = g_strdup ("*");
else
uri_string = soup_uri_get_path_and_query (uri);
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 6cbd5ff9..93e45d9e 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -140,8 +140,6 @@ void soup_message_set_reason_phrase (SoupMessage *ms
void soup_message_set_method (SoupMessage *msg,
const char *method);
-gboolean soup_message_is_options_ping (SoupMessage *msg);
-
void soup_message_set_http_version (SoupMessage *msg,
SoupHTTPVersion version);
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index eab0c4af..e52cfde1 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -91,7 +91,7 @@ typedef struct {
SoupMessagePriority priority;
gboolean is_top_level_navigation;
- gboolean options_ping;
+ gboolean is_options_ping;
} SoupMessagePrivate;
G_DEFINE_TYPE_WITH_PRIVATE (SoupMessage, soup_message, G_TYPE_OBJECT)
@@ -137,7 +137,7 @@ enum {
PROP_PRIORITY,
PROP_SITE_FOR_COOKIES,
PROP_IS_TOP_LEVEL_NAVIGATION,
- PROP_OPTIONS_PING,
+ PROP_IS_OPTIONS_PING,
LAST_PROP
};
@@ -189,7 +189,6 @@ soup_message_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
SoupMessage *msg = SOUP_MESSAGE (object);
- SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
switch (prop_id) {
case PROP_METHOD:
@@ -216,8 +215,8 @@ soup_message_set_property (GObject *object, guint prop_id,
case PROP_PRIORITY:
soup_message_set_priority (msg, g_value_get_enum (value));
break;
- case PROP_OPTIONS_PING:
- priv->options_ping = g_value_get_boolean (value);
+ case PROP_IS_OPTIONS_PING:
+ soup_message_set_is_options_ping (msg, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -275,8 +274,8 @@ soup_message_get_property (GObject *object, guint prop_id,
case PROP_PRIORITY:
g_value_set_enum (value, priv->priority);
break;
- case PROP_OPTIONS_PING:
- g_value_set_boolean (value, priv->options_ping);
+ case PROP_IS_OPTIONS_PING:
+ g_value_set_boolean (value, priv->is_options_ping);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -754,16 +753,17 @@ soup_message_class_init (SoupMessageClass *message_class)
G_PARAM_STATIC_STRINGS));
/**
- * SoupMessage:options-ping:
+ * SoupMessage:is-options-ping:
*
* The #SoupMessage is intended to be used to send
- * `OPTIONS *` to a server and the path of
- * #SoupMessage:uri will be ignored.
+ * `OPTIONS *` to a server. When set to %TRUE, the
+ * path of #SoupMessage:uri will be ignored and
+ * #SoupMessage:method set to %SOUP_METHOD_OPTIONS.
*/
g_object_class_install_property (
- object_class, PROP_OPTIONS_PING,
- g_param_spec_boolean ("options-ping",
- "Options Ping",
+ object_class, PROP_IS_OPTIONS_PING,
+ g_param_spec_boolean ("is-options-ping",
+ "Is Options Ping",
"The message is an OPTIONS ping",
FALSE,
G_PARAM_READWRITE |
@@ -778,7 +778,7 @@ soup_message_class_init (SoupMessageClass *message_class)
*
* Creates a new empty #SoupMessage, which will connect to @uri
*
- * Returns: (nullable): the new #SoupMessage (or %NULL if @uri
+ * Returns: (transfer full) (nullable): the new #SoupMessage (or %NULL if @uri
* could not be parsed).
*/
SoupMessage *
@@ -810,17 +810,41 @@ soup_message_new (const char *method, const char *uri_string)
*
* Creates a new empty #SoupMessage, which will connect to @uri
*
- * Returns: the new #SoupMessage
+ * Returns: (transfer full): the new #SoupMessage
*/
SoupMessage *
soup_message_new_from_uri (const char *method, GUri *uri)
{
+ g_return_val_if_fail (method != NULL, NULL);
+ g_return_val_if_fail (SOUP_URI_IS_VALID (uri), NULL);
+
return g_object_new (SOUP_TYPE_MESSAGE,
"method", method,
"uri", uri,
NULL);
}
+/**
+ * soup_message_new_options_ping:
+ * @base_uri: the destination endpoint (as a #GUri)
+ *
+ * Creates a new #SoupMessage to send `OPTIONS *` to a server. The path of @base_uri
+ * will be ignored.
+ *
+ * Returns: (transfer full): the new #SoupMessage
+ */
+SoupMessage *
+soup_message_new_options_ping (GUri *base_uri)
+{
+ g_return_val_if_fail (SOUP_URI_IS_VALID (base_uri), NULL);
+
+ return g_object_new (SOUP_TYPE_MESSAGE,
+ "method", SOUP_METHOD_OPTIONS,
+ "uri", base_uri,
+ "is-options-ping", TRUE,
+ NULL);
+}
+
/**
* soup_message_new_from_encoded_form:
* @method: the HTTP method for the created request (GET, POST or PUT)
@@ -2239,10 +2263,49 @@ soup_message_set_method (SoupMessage *msg,
g_object_notify (G_OBJECT (msg), "method");
}
+/**
+ * soup_message_get_is_options_ping:
+ * @msg: a #SoupMessage
+ *
+ * Gets whether @msg is intended to be used to send `OPTIONS *` to a server.
+ *
+ * Returns: %TRUE if the message is options ping, or %FALSE otherwise
+ */
gboolean
-soup_message_is_options_ping (SoupMessage *msg)
+soup_message_get_is_options_ping (SoupMessage *msg)
{
- SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
+ SoupMessagePrivate *priv;
+
+ g_return_val_if_fail (SOUP_IS_MESSAGE (msg), FALSE);
+
+ priv = soup_message_get_instance_private (msg);
+
+ return priv->is_options_ping;
+}
+
+/**
+ * soup_message_set_is_options_ping:
+ * @msg: a #SoupMessage
+ * @is_options_ping: the value to set
+ *
+ * Set whether @msg is intended to be used to send `OPTIONS *` to a server.
+ * When set to %TRUE, the path of #SoupMessage:uri will be ignored and
+ * #SoupMessage:method set to %SOUP_METHOD_OPTIONS.
+ */
+void
+soup_message_set_is_options_ping (SoupMessage *msg,
+ gboolean is_options_ping)
+{
+ SoupMessagePrivate *priv;
+
+ g_return_if_fail (SOUP_IS_MESSAGE (msg));
+
+ priv = soup_message_get_instance_private (msg);
+ if (priv->is_options_ping == is_options_ping)
+ return;
- return priv->options_ping;
+ priv->is_options_ping = is_options_ping;
+ g_object_notify (G_OBJECT (msg), "is-options-ping");
+ if (priv->is_options_ping)
+ soup_message_set_method (msg, SOUP_METHOD_OPTIONS);
}
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index ff2c471e..008ea5a2 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -24,6 +24,9 @@ SOUP_AVAILABLE_IN_ALL
SoupMessage *soup_message_new_from_uri (const char *method,
GUri *uri);
+SOUP_AVAILABLE_IN_ALL
+SoupMessage *soup_message_new_options_ping (GUri *base_uri);
+
SOUP_AVAILABLE_IN_ALL
SoupMessage *soup_message_new_from_encoded_form (const char *method,
const char *uri_string,
@@ -159,4 +162,11 @@ SoupMessageHeaders *soup_message_get_request_headers (SoupMessage *msg);
SOUP_AVAILABLE_IN_ALL
SoupMessageHeaders *soup_message_get_response_headers (SoupMessage *msg);
+SOUP_AVAILABLE_IN_ALL
+gboolean soup_message_get_is_options_ping (SoupMessage *msg);
+
+SOUP_AVAILABLE_IN_ALL
+void soup_message_set_is_options_ping (SoupMessage *msg,
+ gboolean is_options_ping);
+
G_END_DECLS
diff --git a/tests/server-test.c b/tests/server-test.c
index cd159151..2f9c4997 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -134,11 +134,8 @@ do_star_test (ServerData *sd, gconstpointer test_data)
session = soup_test_session_new (NULL);
debug_printf (1, " Testing with no handler\n");
- msg = g_object_new (SOUP_TYPE_MESSAGE,
- "method", SOUP_METHOD_OPTIONS,
- "uri", sd->base_uri,
- "options-ping", TRUE,
- NULL);
+ msg = soup_message_new_options_ping (sd->base_uri);
+ g_assert_true (soup_message_get_is_options_ping (msg));
soup_test_session_send_message (session, msg);
soup_test_assert_message_status (msg, SOUP_STATUS_NOT_FOUND);
@@ -148,11 +145,10 @@ do_star_test (ServerData *sd, gconstpointer test_data)
server_add_handler (sd, "*", server_star_callback, NULL, NULL);
debug_printf (1, " Testing with handler\n");
- msg = g_object_new (SOUP_TYPE_MESSAGE,
- "method", SOUP_METHOD_OPTIONS,
- "uri", sd->base_uri,
- "options-ping", TRUE,
- NULL);
+ msg = soup_message_new_from_uri ("GET", sd->base_uri);
+ g_assert_false (soup_message_get_is_options_ping (msg));
+ soup_message_set_is_options_ping (msg, TRUE);
+ g_assert_true (soup_message_get_is_options_ping (msg));
soup_test_session_send_message (session, msg);
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]