Commit 73e75861 authored by Patrick Griffis's avatar Patrick Griffis Committed by Carlos Garcia Campos
Browse files

content-decoder: Only advertise brotli support over TLS

parent 1a6bbe6a
Pipeline #287309 passed with stages
in 5 minutes and 20 seconds
......@@ -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);
}
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment