diff --git a/src/common/cockpitwebserver.c b/src/common/cockpitwebserver.c index 7b3e0c52ddd2..c6a7492198a3 100644 --- a/src/common/cockpitwebserver.c +++ b/src/common/cockpitwebserver.c @@ -742,43 +742,23 @@ cockpit_web_request_process_delayed_reply (CockpitWebRequest *self, const gchar *path, GHashTable *headers) { - CockpitWebResponse *response; - const gchar *host; - const gchar *body; - GBytes *bytes; - gsize length; - gchar *url; - g_assert (self->delayed_reply > 299); - response = cockpit_web_request_respond (self); + g_autoptr(CockpitWebResponse) response = cockpit_web_request_respond (self); g_signal_connect_data (response, "done", G_CALLBACK (on_web_response_done), g_object_ref (self->web_server), (GClosureNotify)g_object_unref, 0); if (self->delayed_reply == 301) { - body = "Moved" - "Please use TLS"; - host = g_hash_table_lookup (headers, "Host"); - url = g_strdup_printf ("https://%s%s", - host != NULL ? host : "", path); - length = strlen (body); - cockpit_web_response_headers (response, 301, "Moved Permanently", length, - "Content-Type", "text/html", - "Location", url, - NULL); - g_free (url); - bytes = g_bytes_new_static (body, length); - if (cockpit_web_response_queue (response, bytes)) - cockpit_web_response_complete (response); - g_bytes_unref (bytes); + const gchar *host = g_hash_table_lookup (headers, "Host"); + g_autofree gchar *url = g_strdup_printf ("https://%s%s", host != NULL ? host : "", path); + cockpit_web_response_headers (response, 301, "Moved Permanently", 0, "Location", url, NULL); + cockpit_web_response_complete (response); } else { cockpit_web_response_error (response, self->delayed_reply, NULL, NULL); } - - g_object_unref (response); } static gboolean