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

[tor-commits] [tor/master] Try not to mess up caches with the X-Or-Diff-From-Consensus header



commit da6b00443c266f1f0928ae02c3832123cbaa9455
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu May 4 11:25:33 2017 -0400

    Try not to mess up caches with the X-Or-Diff-From-Consensus header
---
 src/or/directory.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/or/directory.c b/src/or/directory.c
index 4537d79..aca3030 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -3288,8 +3288,9 @@ write_http_response_header_impl(dir_connection_t *conn, ssize_t length,
 /** As write_http_response_header_impl, but sets encoding and content-typed
  * based on whether the response will be <b>compressed</b> or not. */
 static void
-write_http_response_header(dir_connection_t *conn, ssize_t length,
-                           compress_method_t method, long cache_lifetime)
+write_http_response_headers(dir_connection_t *conn, ssize_t length,
+                            compress_method_t method,
+                            const char *extra_headers, long cache_lifetime)
 {
   const char *methodname = compression_method_get_name(method);
   const char *doctype;
@@ -3300,10 +3301,19 @@ write_http_response_header(dir_connection_t *conn, ssize_t length,
   write_http_response_header_impl(conn, length,
                                   doctype,
                                   methodname,
-                                  NULL,
+                                  extra_headers,
                                   cache_lifetime);
 }
 
+/** As write_http_response_headers, but assumes extra_headers is NULL */
+static void
+write_http_response_header(dir_connection_t *conn, ssize_t length,
+                           compress_method_t method,
+                           long cache_lifetime)
+{
+  write_http_response_headers(conn, length, method, NULL, cache_lifetime);
+}
+
 /** Array of compression methods to use (if supported) for serving
  * precompressed data, ordered from best to worst. */
 static compress_method_t srv_meth_pref_precompressed[] = {
@@ -4056,14 +4066,19 @@ handle_get_current_consensus(dir_connection_t *conn,
                          DIRREQ_DIRECT);
   }
 
+  /* Use this header to tell caches that the response depends on the
+   * X-Or-Diff-From-Consensus header (or lack thereof). */
+  const char vary_header[] = "Vary: X-Or-Diff-From-Consensus\r\n";
+
   clear_spool = 0;
 
   // The compress_method might have been NO_METHOD, but we store the data
   // compressed. Decompress them using `compression_used`. See fallback code in
   // find_best_consensus() and find_best_diff().
-  write_http_response_header(conn, -1,
+  write_http_response_headers(conn, -1,
                              compress_method == NO_METHOD ?
                                NO_METHOD : compression_used,
+                             vary_header,
                              smartlist_len(conn->spool) == 1 ? lifetime : 0);
 
   if (compress_method == NO_METHOD)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits