[libsoup/pgriffis/connection-id] Add soup_message_get_connection_id() API This is useful for WebKit to show in its inspector for easy
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/pgriffis/connection-id] Add soup_message_get_connection_id() API This is useful for WebKit to show in its inspector for easy
- Date: Mon, 29 Mar 2021 17:40:49 +0000 (UTC)
commit 532f8d4f304f26c4501aec49ee2d42d1b802daee
Author: Patrick Griffis <pgriffis igalia com>
Date: Mon Mar 29 12:38:42 2021 -0500
Add soup_message_get_connection_id() API
This is useful for WebKit to show in its inspector for easy debugging.
docs/reference/libsoup-3.0-sections.txt | 1 +
libsoup/soup-connection.c | 24 ++++++++++++++++++++++++
libsoup/soup-connection.h | 3 +++
libsoup/soup-message.c | 23 +++++++++++++++++++++++
libsoup/soup-message.h | 6 +-----
libsoup/soup-session.c | 2 ++
6 files changed, 54 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt
index 77e03b56..26775111 100644
--- a/docs/reference/libsoup-3.0-sections.txt
+++ b/docs/reference/libsoup-3.0-sections.txt
@@ -27,6 +27,7 @@ soup_message_get_request_headers
soup_message_get_response_headers
<SUBSECTION>
soup_message_is_keepalive
+soup_message_get_connection_id
soup_message_get_tls_certificate
soup_message_get_tls_certificate_errors
<SUBSECTION>
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index 60384fdf..06fa7117 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -26,6 +26,7 @@ typedef struct {
GSocketConnectable *remote_connectable;
GIOStream *iostream;
SoupSocketProperties *socket_props;
+ guint64 id;
GUri *proxy_uri;
gboolean ssl;
@@ -53,6 +54,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
enum {
PROP_0,
+ PROP_ID,
PROP_REMOTE_CONNECTABLE,
PROP_SOCKET_PROPERTIES,
PROP_STATE,
@@ -131,6 +133,9 @@ soup_connection_set_property (GObject *object, guint prop_id,
case PROP_SSL:
priv->ssl = g_value_get_boolean (value);
break;
+ case PROP_ID:
+ priv->id = g_value_get_uint64 (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -156,6 +161,9 @@ soup_connection_get_property (GObject *object, guint prop_id,
case PROP_SSL:
g_value_set_boolean (value, priv->ssl);
break;
+ case PROP_ID:
+ g_value_set_uint64 (value, priv->id);
+ break;
case PROP_TLS_CERTIFICATE:
g_value_set_object (value, soup_connection_get_tls_certificate (SOUP_CONNECTION (object)));
break;
@@ -241,6 +249,14 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
"Whether the connection should use TLS",
FALSE,G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (
+ object_class, PROP_ID,
+ g_param_spec_uint64 ("id",
+ "Connection Identifier",
+ "Unique identifier for the connection",
+ 0, G_MAXUINT64,
+ 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
object_class, PROP_TLS_CERTIFICATE,
g_param_spec_object ("tls-certificate",
@@ -1083,3 +1099,11 @@ soup_connection_get_tls_certificate_errors (SoupConnection *conn)
return g_tls_connection_get_peer_certificate_errors (G_TLS_CONNECTION (priv->connection));
}
+
+guint64
+soup_connection_get_id (SoupConnection *conn)
+{
+ SoupConnectionPrivate *priv = soup_connection_get_instance_private (conn);
+
+ return priv->id;
+}
diff --git a/libsoup/soup-connection.h b/libsoup/soup-connection.h
index 04c9353b..410bde0e 100644
--- a/libsoup/soup-connection.h
+++ b/libsoup/soup-connection.h
@@ -75,6 +75,9 @@ void soup_connection_send_request (SoupConnection *conn,
GTlsCertificate *soup_connection_get_tls_certificate (SoupConnection *conn);
GTlsCertificateFlags soup_connection_get_tls_certificate_errors (SoupConnection *conn);
+
+guint64 soup_connection_get_id (SoupConnection *conn);
+
G_END_DECLS
#endif /* __SOUP_CONNECTION_H__ */
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index e52cfde1..88d777cb 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -2309,3 +2309,26 @@ soup_message_set_is_options_ping (SoupMessage *msg,
if (priv->is_options_ping)
soup_message_set_method (msg, SOUP_METHOD_OPTIONS);
}
+
+/**
+ * soup_message_get_connection_id:
+ * @msg: The #SoupMessage
+ *
+ * Returns the unique idenfier for the connection used.
+ *
+ * Returns: An id or 0 if no connection.
+ */
+guint64
+soup_message_get_connection_id (SoupMessage *msg)
+{
+ SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
+
+ g_return_val_if_fail (SOUP_IS_MESSAGE (msg), 0);
+
+ SoupConnection *conn = priv->connection;
+
+ if (!conn)
+ return 0;
+
+ return soup_connection_get_id (conn);
+}
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index 008ea5a2..0e4048d3 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -163,10 +163,6 @@ 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);
+guint64 soup_message_get_connection_id (SoupMessage *msg);
G_END_DECLS
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index df9b1ad8..06374dd5 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -121,6 +121,7 @@ typedef struct {
GHashTable *conns; /* SoupConnection -> SoupSessionHost */
guint num_conns;
guint max_conns, max_conns_per_host;
+ guint64 last_connection_id;
} SoupSessionPrivate;
static void free_host (SoupSessionHost *host);
@@ -1862,6 +1863,7 @@ get_connection_for_host (SoupSession *session,
ensure_socket_props (session);
conn = g_object_new (SOUP_TYPE_CONNECTION,
+ "id", ++priv->last_connection_id,
"remote-connectable", remote_connectable,
"ssl", soup_uri_is_https (host->uri),
"socket-properties", priv->socket_props,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]