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

[tor-commits] [tor/master] New function to add additional headers to a directory request



commit 57710c15875cfe9bdb1f1b2b6f6fa1346ab46c11
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed May 3 14:04:04 2017 -0400

    New function to add additional headers to a directory request
---
 src/or/directory.c | 24 ++++++++++++++++++++++++
 src/or/directory.h |  4 +++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/or/directory.c b/src/or/directory.c
index cf272f7..8f934bd 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -989,6 +989,9 @@ struct directory_request_t {
   time_t if_modified_since;
   /** Hidden-service-specific information */
   const rend_data_t *rend_query;
+  /** Extra headers to append to the request */
+  config_line_t *additional_headers;
+  /** */
   /** Used internally to directory.c: gets informed when the attempt to
    * connect to the directory succeeds or fails, if that attempt bears on the
    * directory's usability as a directory guard. */
@@ -1087,6 +1090,7 @@ directory_request_free(directory_request_t *req)
 {
   if (req == NULL)
     return;
+  config_free_lines(req->additional_headers);
   tor_free(req);
 }
 /**
@@ -1187,6 +1191,18 @@ directory_request_set_if_modified_since(directory_request_t *req,
 {
   req->if_modified_since = if_modified_since;
 }
+
+/** Include a header of name <b>key</b> with content <b>val</b> in the
+ * request. Neither may include newlines or other odd characters. Their
+ * ordering is not currently guaranteed.
+ */
+void
+directory_request_add_header(directory_request_t *req,
+                             const char *key,
+                             const char *val)
+{
+  config_line_prepend(&req->additional_headers, key, val);
+}
 /**
  * Set an object containing HS data to be associated with this request.  Note
  * that only an alias to <b>query</b> is stored, so the <b>query</b> object
@@ -1673,6 +1689,14 @@ directory_send_command(dir_connection_t *conn,
     proxystring[0] = 0;
   }
 
+  /* Add additional headers, if any */
+  {
+    config_line_t *h;
+    for (h = req->additional_headers; h; h = h->next) {
+      smartlist_add_asprintf(headers, "%s: %s\r\n", h->key, h->value);
+    }
+  }
+
   switch (purpose) {
     case DIR_PURPOSE_FETCH_CONSENSUS:
       /* resource is optional.  If present, it's a flavor name */
diff --git a/src/or/directory.h b/src/or/directory.h
index 8473d39..125333d 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -72,7 +72,9 @@ void directory_request_set_rend_query(directory_request_t *req,
 
 void directory_request_set_routerstatus(directory_request_t *req,
                                         const routerstatus_t *rs);
-
+void directory_request_add_header(directory_request_t *req,
+                                  const char *key,
+                                  const char *val);
 MOCK_DECL(void, directory_initiate_request, (directory_request_t *request));
 
 int parse_http_response(const char *headers, int *code, time_t *date,



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