diff options
author | Roger Dingledine <arma@torproject.org> | 2005-05-20 08:51:45 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2005-05-20 08:51:45 +0000 |
commit | f0e309e5bdb9227ed73a59e983da83771c062941 (patch) | |
tree | 8b34cccb7501e269d254901af3f8c30cc891c018 /src/or/directory.c | |
parent | 918c5a9115c1e39e8ef28e6241cfcd7bdaf5374b (diff) | |
download | tor-f0e309e5bdb9227ed73a59e983da83771c062941.tar.gz tor-f0e309e5bdb9227ed73a59e983da83771c062941.zip |
add HttpProxyAuthenticator config option too
svn:r4272
Diffstat (limited to 'src/or/directory.c')
-rw-r--r-- | src/or/directory.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 1ace18ab55..3a4da0c04e 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -363,7 +363,8 @@ directory_send_command(connection_t *conn, const char *platform, int purpose, const char *resource, const char *payload, size_t payload_len) { char tmp[8192]; - char proxystring[128]; + char proxystring[256]; + char proxyauthstring[256]; char hoststring[128]; char url[128]; const char *httpcommand = NULL; @@ -371,15 +372,35 @@ directory_send_command(connection_t *conn, const char *platform, tor_assert(conn); tor_assert(conn->type == CONN_TYPE_DIR); + /* come up with a string for which Host: we want */ if (conn->port == 80) { strlcpy(hoststring, conn->address, sizeof(hoststring)); } else { tor_snprintf(hoststring, sizeof(hoststring),"%s:%d",conn->address, conn->port); } + + /* come up with some proxy lines, if we're using one. */ if (get_options()->HttpProxy) { + char *base64_authenticator=NULL; + const char *authenticator = get_options()->HttpProxyAuthenticator; + tor_snprintf(proxystring, sizeof(proxystring),"http://%s", hoststring); + if (authenticator) { + base64_authenticator = alloc_http_authenticator(authenticator); + if (!base64_authenticator) + log_fn(LOG_WARN, "Encoding http authenticator failed"); + } + if (base64_authenticator) { + tor_snprintf(proxyauthstring, sizeof(proxyauthstring), + "\r\nProxy-Authorization: Basic %s", + base64_authenticator); + tor_free(base64_authenticator); + } else { + proxyauthstring[0] = 0; + } } else { proxystring[0] = 0; + proxyauthstring[0] = 0; } switch (purpose) { @@ -424,12 +445,13 @@ directory_send_command(connection_t *conn, const char *platform, break; } - tor_snprintf(tmp, sizeof(tmp), "%s %s%s HTTP/1.0\r\nContent-Length: %lu\r\nHost: %s\r\n\r\n", + tor_snprintf(tmp, sizeof(tmp), "%s %s%s HTTP/1.0\r\nContent-Length: %lu\r\nHost: %s%s\r\n\r\n", httpcommand, proxystring, url, payload ? (unsigned long)payload_len : 0, - hoststring); + hoststring, + proxyauthstring); connection_write_to_buf(tmp, strlen(tmp), conn); if (payload) { |