[libsoup/pgriffis/brotli-over-tls: 12/12] content-decoder: Only advertise brotli support over TLS




commit 73e758616c84d11d35ae5f0e958ae2828581b6b1
Author: Patrick Griffis <pgriffis igalia com>
Date:   Tue Jun 1 21:18:11 2021 -0500

    content-decoder: Only advertise brotli support over TLS

 libsoup/content-decoder/soup-content-decoder.c | 22 ++++++++++++++--------
 tests/logger-test.c                            |  8 --------
 2 files changed, 14 insertions(+), 16 deletions(-)
---
diff --git a/libsoup/content-decoder/soup-content-decoder.c b/libsoup/content-decoder/soup-content-decoder.c
index ac680d6f..7f36d0cf 100644
--- a/libsoup/content-decoder/soup-content-decoder.c
+++ b/libsoup/content-decoder/soup-content-decoder.c
@@ -14,6 +14,7 @@
 #include "soup-session-feature-private.h"
 #include "soup-message-private.h"
 #include "soup-headers.h"
+#include "soup-uri-utils-private.h"
 #ifdef WITH_BROTLI
 #include "soup-brotli-decompressor.h"
 #endif
@@ -176,13 +177,6 @@ soup_content_decoder_content_processor_init (SoupContentProcessorInterface *proc
        processor_interface->wrap_input = soup_content_decoder_content_processor_wrap_input;
 }
 
-/* This is constant for now */
-#ifdef WITH_BROTLI
-#define ACCEPT_ENCODING_HEADER "gzip, deflate, br"
-#else
-#define ACCEPT_ENCODING_HEADER "gzip, deflate"
-#endif
-
 static GConverter *
 gzip_decoder_creator (void)
 {
@@ -247,9 +241,21 @@ soup_content_decoder_request_queued (SoupSessionFeature *feature,
 {
        if (!soup_message_headers_get_one (soup_message_get_request_headers (msg),
                                           "Accept-Encoding")) {
+                const char *header = "gzip, deflate";
+
+#ifdef WITH_BROTLI
+                /* brotli is only enabled over TLS connections
+                 * as other browsers have found that some networks have expectations
+                 * regarding the encoding of HTTP messages and this may break those
+                 * expectations. Firefox and Chromium behave similarly.
+                 */
+                if (soup_uri_is_https (soup_message_get_uri (msg)))
+                        header = "gzip, deflate, br";
+#endif
+
                soup_message_headers_append (soup_message_get_request_headers (msg),
                                             "Accept-Encoding",
-                                            ACCEPT_ENCODING_HEADER);
+                                            header);
        }
 }
 
diff --git a/tests/logger-test.c b/tests/logger-test.c
index ee9707a0..19145b21 100644
--- a/tests/logger-test.c
+++ b/tests/logger-test.c
@@ -143,11 +143,7 @@ do_logger_headers_test (void)
         host = g_strdup_printf ("127.0.0.1:%d", g_uri_get_port (base_uri));
         g_assert_cmpstr (g_hash_table_lookup (log.request, "Host"), ==, host);
         g_free (host);
-#ifdef WITH_BROTLI
-        g_assert_cmpstr (g_hash_table_lookup (log.request, "Accept-Encoding"), ==, "gzip, deflate, br");
-#else
         g_assert_cmpstr (g_hash_table_lookup (log.request, "Accept-Encoding"), ==, "gzip, deflate");
-#endif
         g_assert_cmpstr (g_hash_table_lookup (log.request, "Connection"), ==, "Keep-Alive");
 
         g_assert_nonnull (log.response);
@@ -217,11 +213,7 @@ do_logger_body_test (void)
         host = g_strdup_printf ("127.0.0.1:%d", g_uri_get_port (base_uri));
         g_assert_cmpstr (g_hash_table_lookup (log.request, "Host"), ==, host);
         g_free (host);
-#ifdef WITH_BROTLI
-        g_assert_cmpstr (g_hash_table_lookup (log.request, "Accept-Encoding"), ==, "gzip, deflate, br");
-#else
         g_assert_cmpstr (g_hash_table_lookup (log.request, "Accept-Encoding"), ==, "gzip, deflate");
-#endif
         g_assert_cmpstr (g_hash_table_lookup (log.request, "Connection"), ==, "Keep-Alive");
         g_assert_cmpint (atoi (g_hash_table_lookup (log.request, "Content-Length")), ==, sizeof (body_data) 
- 1);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]