aboutsummaryrefslogtreecommitdiff
path: root/src/or/directory.c
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2017-05-11 01:43:37 +0200
committerAlexander Færøy <ahf@torproject.org>2017-05-12 17:18:45 +0200
commita3a31fa120a62d51e136317df84a7202dfad214d (patch)
tree6c7987c2ff98c5cd65f182cf5a4af4c301f48db7 /src/or/directory.c
parent630563719728e039364b1e4cc2ada9017405a383 (diff)
downloadtor-a3a31fa120a62d51e136317df84a7202dfad214d.tar.gz
tor-a3a31fa120a62d51e136317df84a7202dfad214d.zip
Send "Accept-Encoding" to directory servers.
See: https://bugs.torproject.org/21667
Diffstat (limited to 'src/or/directory.c')
-rw-r--r--src/or/directory.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 56d1cca333..ca493888c2 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -1667,6 +1667,7 @@ directory_send_command(dir_connection_t *conn,
char decorated_address[128];
smartlist_t *headers = smartlist_new();
char *url;
+ char *accept_encoding;
size_t url_len;
char request[8192];
size_t request_len, total_request_len = 0;
@@ -1723,6 +1724,12 @@ directory_send_command(dir_connection_t *conn,
proxystring[0] = 0;
}
+ /* Add Accept-Encoding. */
+ accept_encoding = accept_encoding_header();
+ smartlist_add_asprintf(headers, "Accept-Encoding: %s\r\n",
+ accept_encoding);
+ tor_free(accept_encoding);
+
/* Add additional headers, if any */
{
config_line_t *h;
@@ -3333,6 +3340,29 @@ parse_accept_encoding_header(const char *h)
return result;
}
+/** Return a newly allocated string containing a comma separated list of
+ * supported encodings. */
+STATIC char *
+accept_encoding_header(void)
+{
+ smartlist_t *methods = smartlist_new();
+ char *header = NULL;
+ compress_method_t method;
+
+ // FIXME(ahf): Should we rename `srv_meth_pref_precompressed` and use this
+ // instead to define the order in the directory module rather than the order
+ // defined in the compression module?
+ for (method = UNKNOWN_METHOD; method > NO_METHOD; --method) {
+ if (tor_compress_supports_method(method))
+ smartlist_add(methods, (char *)compression_method_get_name(method));
+ }
+
+ header = smartlist_join_strings(methods, ", ", 0, NULL);
+ smartlist_free(methods);
+
+ return header;
+}
+
/** Decide whether a client would accept the consensus we have.
*
* Clients can say they only want a consensus if it's signed by more