aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-05-03 14:04:04 -0400
committerNick Mathewson <nickm@torproject.org>2017-05-04 08:37:41 -0400
commit57710c15875cfe9bdb1f1b2b6f6fa1346ab46c11 (patch)
treec19e09774fb562ded0532877824385f362ce3554 /src
parent112286338b61ed747572cfa67ac38e2052e7c807 (diff)
downloadtor-57710c15875cfe9bdb1f1b2b6f6fa1346ab46c11.tar.gz
tor-57710c15875cfe9bdb1f1b2b6f6fa1346ab46c11.zip
New function to add additional headers to a directory request
Diffstat (limited to 'src')
-rw-r--r--src/or/directory.c24
-rw-r--r--src/or/directory.h4
2 files changed, 27 insertions, 1 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index cf272f731c..8f934bdcdd 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 8473d39e85..125333da37 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,