[libsoup] Readd soup_uri_get_host_for_headers()
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Readd soup_uri_get_host_for_headers()
- Date: Fri, 4 Dec 2020 17:22:14 +0000 (UTC)
commit bdf52faffe2258fb93a5d07ee1b2750d005a0c36
Author: Patrick Griffis <pgriffis igalia com>
Date: Fri Dec 4 11:21:20 2020 -0600
Readd soup_uri_get_host_for_headers()
libsoup/soup-logger.c | 10 ++--------
libsoup/soup-message-io.c | 11 +++--------
libsoup/soup-uri-utils-private.h | 2 ++
libsoup/soup-uri-utils.c | 13 +++++++++++++
4 files changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index e4f9c276..0ac5bb08 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -516,20 +516,14 @@ print_request (SoupLogger *logger, SoupMessage *msg,
return;
if (!soup_message_headers_get_one (soup_message_get_request_headers (msg), "Host")) {
- char *uri_host = (char*)g_uri_get_host (uri);
-
- if (strchr (uri_host, ':'))
- uri_host = g_strdup_printf ("[%s]", uri_host);
- else if (g_hostname_is_non_ascii (uri_host))
- uri_host = g_hostname_to_ascii (uri_host);
+ char *uri_host = soup_uri_get_host_for_headers (uri);
soup_logger_print (logger, SOUP_LOGGER_LOG_HEADERS, '>',
"Host: %s%c%u", uri_host,
soup_uri_uses_default_port (uri) ? '\0' : ':',
g_uri_get_port (uri));
- if (uri_host != g_uri_get_host (uri))
- g_free (uri_host);
+ g_free (uri_host);
}
soup_message_headers_iter_init (&iter, soup_message_get_request_headers (msg));
while (soup_message_headers_iter_next (&iter, &name, &value)) {
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index 1055c099..4ca638c0 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -259,16 +259,12 @@ write_headers (SoupMessage *msg,
SoupEncoding *encoding)
{
GUri *uri = soup_message_get_uri (msg);
- char *uri_host;
+ char *uri_host;
char *uri_string;
SoupMessageHeadersIter iter;
const char *name, *value;
- uri_host = (char*)g_uri_get_host (uri);
- if (strchr (uri_host, ':'))
- uri_host = g_strdup_printf ("[%.*s]", (int) strcspn (uri_host, "%"), uri_host);
- else if (g_hostname_is_non_ascii (uri_host))
- uri_host = g_hostname_to_ascii (uri_host);
+ uri_host = soup_uri_get_host_for_headers (uri);
if (soup_message_get_method (msg) == SOUP_METHOD_CONNECT) {
/* CONNECT URI is hostname:port for tunnel destination */
@@ -308,8 +304,7 @@ write_headers (SoupMessage *msg,
}
}
g_free (uri_string);
- if (uri_host != g_uri_get_host (uri))
- g_free (uri_host);
+ g_free (uri_host);
*encoding = soup_message_headers_get_encoding (soup_message_get_request_headers (msg));
diff --git a/libsoup/soup-uri-utils-private.h b/libsoup/soup-uri-utils-private.h
index b741a6d7..6bc2b38d 100644
--- a/libsoup/soup-uri-utils-private.h
+++ b/libsoup/soup-uri-utils-private.h
@@ -28,6 +28,8 @@ gboolean soup_uri_host_equal (gconstpointer v1, gconstpointer v2)
GUri *soup_uri_copy_with_normalized_flags (GUri *uri);
+char *soup_uri_get_host_for_headers (GUri *uri);
+
#define SOUP_URI_IS_VALID(x) (x && g_uri_get_host(x) && g_uri_get_host(x)[0])
G_END_DECLS
diff --git a/libsoup/soup-uri-utils.c b/libsoup/soup-uri-utils.c
index 4bc4c11c..de4a162a 100644
--- a/libsoup/soup-uri-utils.c
+++ b/libsoup/soup-uri-utils.c
@@ -489,3 +489,16 @@ soup_uri_copy_with_normalized_flags (GUri *uri)
g_uri_get_fragment (uri)
);
}
+
+char *
+soup_uri_get_host_for_headers (GUri *uri)
+{
+ const char *host = g_uri_get_host (uri);
+
+ if (strchr (host, ':'))
+ return g_strdup_printf ("[%.*s]", (int)strcspn (host, "%"), host);
+ if (g_hostname_is_non_ascii (host))
+ return g_hostname_to_ascii (host);
+
+ return g_strdup (host);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]