[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Send "Accept-Encoding" to directory servers.
commit a3a31fa120a62d51e136317df84a7202dfad214d
Author: Alexander Færøy <ahf@xxxxxxxxxxxxxx>
Date: Thu May 11 01:43:37 2017 +0200
Send "Accept-Encoding" to directory servers.
See: https://bugs.torproject.org/21667
---
src/or/directory.c | 30 ++++++++++++++++++++++++++++++
src/or/directory.h | 1 +
2 files changed, 31 insertions(+)
diff --git a/src/or/directory.c b/src/or/directory.c
index 56d1cca..ca49388 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
diff --git a/src/or/directory.h b/src/or/directory.h
index 125333d..a015c70 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -160,6 +160,7 @@ struct get_handler_args_t;
STATIC int handle_get_hs_descriptor_v3(dir_connection_t *conn,
const struct get_handler_args_t *args);
STATIC int directory_handle_command(dir_connection_t *conn);
+STATIC char *accept_encoding_header(void);
#endif
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits