1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Factor out some proxy initialization code for gethttp

* src/http.c (gethttp): Move some initialization code in...
(initialize_proxy_configuration): ... a new function.
This commit is contained in:
Giuseppe Scrivano 2015-03-15 23:03:44 +01:00
parent 29850e77d0
commit f8abb9dd00

View File

@ -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. */