aboutsummaryrefslogtreecommitdiff
path: root/src/feature/dircache/dircache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/feature/dircache/dircache.c')
-rw-r--r--src/feature/dircache/dircache.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c
index d9625ee698..e5ea9f73b3 100644
--- a/src/feature/dircache/dircache.c
+++ b/src/feature/dircache/dircache.c
@@ -1449,14 +1449,28 @@ handle_get_next_bandwidth(dir_connection_t *conn,
(void)args;
log_debug(LD_DIR, "Getting next bandwidth.");
const or_options_t *options = get_options();
+ const compress_method_t compress_method =
+ find_best_compression_method(args->compression_supported, 1);
+
if (options->V3BandwidthsFile) {
int lifetime = 60;
char *bandwidth = read_file_to_str(options->V3BandwidthsFile,
RFTS_IGNORE_MISSING, NULL);
if (bandwidth != NULL) {
- site_t len = strlen(bandwidth);
- write_http_response_header(conn, len, NO_METHOD, lifetime);
- connection_buf_add(bandwidth, len, TO_CONN(conn));
+ ssize_t len = strlen(bandwidth);
+ write_http_response_header(conn, compress_method != NO_METHOD ? -1 : len,
+ compress_method, BANDWIDTH_CACHE_LIFETIME);
+ if (compress_method != NO_METHOD) {
+ conn->compress_state = tor_compress_new(1, compress_method,
+ choose_compression_level(len/2));
+ log_debug(LD_DIR, "Compressing bandwidth file.");
+ connection_buf_add_compress(bandwidth, len, conn, 0);
+ /* Flush the compression state. */
+ connection_buf_add_compress("", 0, conn, 1);
+ } else {
+ log_debug(LD_DIR, "Not compressing bandwidth file.");
+ connection_buf_add(bandwidth, len, TO_CONN(conn));
+ }
tor_free(bandwidth);
return 0;
}