From f8abb9dd00cb18d5594ed16e85d4e847d7cc9e3b Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Sun, 15 Mar 2015 23:03:44 +0100 Subject: [PATCH] Factor out some proxy initialization code for gethttp * src/http.c (gethttp): Move some initialization code in... (initialize_proxy_configuration): ... a new function. --- src/http.c | 63 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/http.c b/src/http.c index 0a1eb78b..1daa852a 100644 --- a/src/http.c +++ b/src/http.c @@ -1778,6 +1778,38 @@ initialize_request (struct url *u, struct http_stat *hs, int *dt, struct url *pr return req; } +static void +initialize_proxy_configuration (struct url *u, struct request *req, + struct url *proxy, char **proxyauth) +{ + char *proxy_user, *proxy_passwd; + /* For normal username and password, URL components override + command-line/wgetrc parameters. With proxy + authentication, it's the reverse, because proxy URLs are + normally the "permanent" ones, so command-line args + should take precedence. */ + if (opt.proxy_user && opt.proxy_passwd) + { + proxy_user = opt.proxy_user; + proxy_passwd = opt.proxy_passwd; + } + else + { + proxy_user = proxy->user; + proxy_passwd = proxy->passwd; + } + /* #### This does not appear right. Can't the proxy request, + say, `Digest' authentication? */ + if (proxy_user && proxy_passwd) + *proxyauth = basic_authentication_encode (proxy_user, proxy_passwd); + + /* Proxy authorization over SSL is handled below. */ +#ifdef HAVE_SSL + if (u->scheme != SCHEME_HTTPS) +#endif + request_set_header (req, "Proxy-Authorization", *proxyauth, rel_value); +} + /* Retrieve a document through HTTP protocol. It recognizes status code, and correctly handles redirections. It closes the network socket. If it receives an error from the functions below it, it @@ -1917,38 +1949,9 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy, proxyauth = NULL; if (proxy) { - char *proxy_user, *proxy_passwd; - /* For normal username and password, URL components override - command-line/wgetrc parameters. With proxy - authentication, it's the reverse, because proxy URLs are - normally the "permanent" ones, so command-line args - should take precedence. */ - if (opt.proxy_user && opt.proxy_passwd) - { - proxy_user = opt.proxy_user; - proxy_passwd = opt.proxy_passwd; - } - else - { - proxy_user = proxy->user; - proxy_passwd = proxy->passwd; - } - /* #### This does not appear right. Can't the proxy request, - say, `Digest' authentication? */ - if (proxy_user && proxy_passwd) - proxyauth = basic_authentication_encode (proxy_user, proxy_passwd); - - /* If we're using a proxy, we will be connecting to the proxy - server. */ conn = proxy; - - /* Proxy authorization over SSL is handled below. */ -#ifdef HAVE_SSL - if (u->scheme != SCHEME_HTTPS) -#endif - request_set_header (req, "Proxy-Authorization", proxyauth, rel_value); + initialize_proxy_configuration (u, req, proxy, &proxyauth); } - keep_alive = true; /* Establish the connection. */