From f7df4e4e1f7314ff309e4d26fcd7f352c33870ef Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <cgarcia@igalia.com>
Date: Wed, 17 Feb 2021 14:08:40 +0100
Subject: [PATCH] content-sniffer: empty resources should be considered
 text/plain

Instead of application/octet-stream according to the HTML5 spec

Conflict: Modify file path adaptation: libsoup/content-sniffer/soup-content-sniffer.c->libsoup/soup-content-sniffer.c
Reference: https://gitlab.gnome.org/GNOME/libsoup/-/commit/f7df4e4e1f7314ff309e4d26fcd7f352c33870ef

---
 libsoup/soup-content-sniffer.c |  2 +-
 tests/sniffing-test.c          | 13 +++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libsoup/soup-content-sniffer.c b/libsoup/soup-content-sniffer.c
index f5a13d18c..948dc182d 100644
--- a/libsoup/soup-content-sniffer.c
+++ b/libsoup/soup-content-sniffer.c
@@ -507,7 +507,7 @@ sniff_unknown (SoupContentSniffer *sniffer, GBytes *buffer,
 	guint i;
 
         if (resource_length == 0)
-                return g_strdup ("application/octet-stream");
+                return g_strdup ("text/plain");
 
 	for (i = 0; i < G_N_ELEMENTS (types_table); i++) {
 		SoupContentSnifferPattern *type_row = &(types_table[i]);
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c
index 1f2bb9115..23e05c1a3 100644
--- a/tests/sniffing-test.c
+++ b/tests/sniffing-test.c
@@ -79,11 +79,13 @@ server_callback (SoupServer        *server,
 	}
 
 	if (g_str_has_prefix (path, "/unknown/")) {
-		char *base_name = g_path_get_basename (path);
+		if (!empty_response) {
+			char *base_name = g_path_get_basename (path);
 
-		response = soup_test_load_resource (base_name, &error);
-		g_assert_no_error (error);
-		g_free (base_name);
+			response = soup_test_load_resource (base_name, &error);
+			g_assert_no_error (error);
+			g_free (base_name);
+		}
 
 		soup_message_headers_append (msg->response_headers,
 					     "Content-Type", "UNKNOWN/unknown");
@@ -439,6 +441,9 @@ main (int argc, char **argv)
 	g_test_add_data_func ("/sniffing/type/unknown-mbox",
 			      "unknown/mbox => text/plain",
 			      do_sniffing_test);
+	g_test_add_data_func ("/sniffing/type/unknown-empty",
+			      "unknown/mbox?empty_response=yes => text/plain",
+			      do_sniffing_test);
 	g_test_add_data_func ("/sniffing/type/unknown-binary",
 			      "unknown/text_binary.txt => application/octet-stream",
 			      do_sniffing_test);
-- 
GitLab

