[libsoup] SoupLogger: fix printing of Host header with IPv6 literal
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] SoupLogger: fix printing of Host header with IPv6 literal
- Date: Sat, 17 Nov 2012 16:38:51 +0000 (UTC)
commit d51d1d2b513439798024cf9474a2ed4f00f4c2d3
Author: Dan Winship <danw gnome org>
Date: Sat Nov 17 11:36:00 2012 -0500
SoupLogger: fix printing of Host header with IPv6 literal
SoupLogger was misprinting Host headers with IPv6 literals (even
though soup-message-client-io was sending them correctly). Fix that.
Also includes an addition to misc-test to verify that the Host header
received by the server is correct (which it already was, but the
SoupLogger bug made me think it wasn't.)
libsoup/soup-logger.c | 14 +++++++++++++-
tests/misc-test.c | 30 +++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index 3183cce..a9f49bf 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -481,10 +481,22 @@ print_request (SoupLogger *logger, SoupMessage *msg,
return;
if (!soup_message_headers_get_one (msg->request_headers, "Host")) {
+ char *uri_host;
+
+ 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);
+ else
+ uri_host = uri->host;
+
soup_logger_print (logger, SOUP_LOGGER_LOG_HEADERS, '>',
- "Host: %s%c%u", uri->host,
+ "Host: %s%c%u", uri_host,
soup_uri_uses_default_port (uri) ? '\0' : ':',
uri->port);
+
+ if (uri_host != uri->host)
+ g_free (uri_host);
}
soup_message_headers_iter_init (&iter, msg->request_headers);
while (soup_message_headers_iter_next (&iter, &name, &value)) {
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 19e9ba0..b564f26 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -1088,6 +1088,34 @@ do_dot_dot_test (void)
}
static void
+ipv6_server_callback (SoupServer *server, SoupMessage *msg,
+ const char *path, GHashTable *query,
+ SoupClientContext *context, gpointer data)
+{
+ const char *host;
+ char expected_host[128];
+
+ host = soup_message_headers_get_one (msg->request_headers, "Host");
+ if (!host) {
+ debug_printf (1, " request has no Host header!\n");
+ errors++;
+ soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
+ return;
+ }
+
+ g_snprintf (expected_host, sizeof (expected_host),
+ "[::1]:%d", soup_server_get_port (server));
+
+ if (strcmp (host, expected_host) == 0)
+ soup_message_set_status (msg, SOUP_STATUS_OK);
+ else {
+ debug_printf (1, " request has incorrect Host header '%s'\n", host);
+ errors++;
+ soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
+ }
+}
+
+static void
do_ipv6_test (void)
{
SoupServer *ipv6_server;
@@ -1103,7 +1131,7 @@ do_ipv6_test (void)
ipv6_server = soup_server_new (SOUP_SERVER_INTERFACE, ipv6_addr,
NULL);
g_object_unref (ipv6_addr);
- soup_server_add_handler (ipv6_server, NULL, server_callback, NULL, NULL);
+ soup_server_add_handler (ipv6_server, NULL, ipv6_server_callback, NULL, NULL);
soup_server_run_async (ipv6_server);
ipv6_uri = soup_uri_new ("http://[::1]/");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]