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




commit b1f992346b90546ff1991d380b43569e51e79158
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 | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/libsoup/content-decoder/soup-content-decoder.c b/libsoup/content-decoder/soup-content-decoder.c
index ac680d6f..b26eb6bb 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
@@ -177,10 +178,11 @@ soup_content_decoder_content_processor_init (SoupContentProcessorInterface *proc
 }
 
 /* This is constant for now */
+#define ACCEPT_ENCODING_HEADER_PLAIN "gzip, deflate"
 #ifdef WITH_BROTLI
-#define ACCEPT_ENCODING_HEADER "gzip, deflate, br"
+#define ACCEPT_ENCODING_HEADER_TLS "gzip, deflate, br"
 #else
-#define ACCEPT_ENCODING_HEADER "gzip, deflate"
+#define ACCEPT_ENCODING_HEADER_TLS ACCEPT_ENCODING_HEADER_PLAIN
 #endif
 
 static GConverter *
@@ -247,9 +249,19 @@ soup_content_decoder_request_queued (SoupSessionFeature *feature,
 {
        if (!soup_message_headers_get_one (soup_message_get_request_headers (msg),
                                           "Accept-Encoding")) {
+                const char *header = ACCEPT_ENCODING_HEADER_PLAIN;
+
+                /* 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 = ACCEPT_ENCODING_HEADER_TLS;
+
                soup_message_headers_append (soup_message_get_request_headers (msg),
                                             "Accept-Encoding",
-                                            ACCEPT_ENCODING_HEADER);
+                                            header);
        }
 }
 


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