Lines 1370-1381
Link Here
|
1370 |
/***************************************************************************** |
1370 |
/***************************************************************************** |
1371 |
* Helper functions for connecting to a server or proxy |
1371 |
* Helper functions for connecting to a server or proxy |
1372 |
*/ |
1372 |
*/ |
|
|
1373 |
static int |
1374 |
http_connect_tunnel(conn_t *conn, struct url *URL, struct url *purl, int isproxyauth) |
1375 |
{ |
1376 |
const char *p; |
1377 |
http_auth_challenges_t proxy_challenges; |
1378 |
init_http_auth_challenges(&proxy_challenges); |
1379 |
http_cmd(conn, "CONNECT %s:%d HTTP/1.1", |
1380 |
URL->host, URL->port); |
1381 |
http_cmd(conn, "Host: %s:%d", |
1382 |
URL->host, URL->port); |
1383 |
if (isproxyauth > 0) |
1384 |
{ |
1385 |
http_auth_params_t aparams; |
1386 |
init_http_auth_params(&aparams); |
1387 |
if (*purl->user || *purl->pwd) { |
1388 |
aparams.user = strdup(purl->user); |
1389 |
aparams.password = strdup(purl->pwd); |
1390 |
} else if ((p = getenv("HTTP_PROXY_AUTH")) != NULL && |
1391 |
*p != '\0') { |
1392 |
if (http_authfromenv(p, &aparams) < 0) { |
1393 |
http_seterr(HTTP_NEED_PROXY_AUTH); |
1394 |
return 999; |
1395 |
} |
1396 |
} else if (fetch_netrc_auth(purl) == 0) { |
1397 |
aparams.user = strdup(purl->user); |
1398 |
aparams.password = strdup(purl->pwd); |
1399 |
} |
1400 |
http_authorize(conn, "Proxy-Authorization", |
1401 |
&proxy_challenges, &aparams, purl); |
1402 |
clean_http_auth_params(&aparams); |
1403 |
} |
1404 |
http_cmd(conn, ""); |
1405 |
return 0; |
1406 |
} |
1373 |
|
1407 |
|
1374 |
/* |
1408 |
/* |
1375 |
* Connect to the correct HTTP server or proxy. |
1409 |
* Connect to the correct HTTP server or proxy. |
1376 |
*/ |
1410 |
*/ |
1377 |
static conn_t * |
1411 |
static conn_t * |
1378 |
http_connect(struct url *URL, struct url *purl, const char *flags) |
1412 |
http_connect(struct url *URL, struct url *purl, const char *flags, int isproxyauth) |
1379 |
{ |
1413 |
{ |
1380 |
struct url *curl; |
1414 |
struct url *curl; |
1381 |
conn_t *conn; |
1415 |
conn_t *conn; |
Lines 1407-1419
Link Here
|
1407 |
return (NULL); |
1441 |
return (NULL); |
1408 |
init_http_headerbuf(&headerbuf); |
1442 |
init_http_headerbuf(&headerbuf); |
1409 |
if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) { |
1443 |
if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) { |
1410 |
http_cmd(conn, "CONNECT %s:%d HTTP/1.1", |
1444 |
if (http_connect_tunnel(conn, URL, purl, isproxyauth) > 0) { |
1411 |
URL->host, URL->port); |
1445 |
fetch_syserr(); |
1412 |
http_cmd(conn, "Host: %s:%d", |
1446 |
goto ouch; |
1413 |
URL->host, URL->port); |
1447 |
} |
1414 |
http_cmd(conn, ""); |
1448 |
/* Get replay from CONNECT Tunnel attempt */ |
1415 |
if (http_get_reply(conn) != HTTP_OK) { |
1449 |
int httpreply = http_get_reply(conn); |
1416 |
http_seterr(conn->err); |
1450 |
if (httpreply != HTTP_OK) { |
|
|
1451 |
http_seterr(httpreply); |
1452 |
/* If the error is a 407/HTTP_NEED_PROXY_AUTH */ |
1453 |
if (httpreply == HTTP_NEED_PROXY_AUTH) |
1454 |
goto proxyauth; |
1417 |
goto ouch; |
1455 |
goto ouch; |
1418 |
} |
1456 |
} |
1419 |
/* Read and discard the rest of the proxy response */ |
1457 |
/* Read and discard the rest of the proxy response */ |
Lines 1453-1458
Link Here
|
1453 |
fetch_close(conn); |
1491 |
fetch_close(conn); |
1454 |
errno = serrno; |
1492 |
errno = serrno; |
1455 |
return (NULL); |
1493 |
return (NULL); |
|
|
1494 |
proxyauth: |
1495 |
/* returning a "dummy" object with error |
1496 |
* set to 407/HTTP_NEED_PROXY_AUTH */ |
1497 |
serrno = errno; |
1498 |
clean_http_headerbuf(&headerbuf); |
1499 |
fetch_close(conn); |
1500 |
errno = serrno; |
1501 |
conn->err = HTTP_NEED_PROXY_AUTH; |
1502 |
return (conn); |
1456 |
} |
1503 |
} |
1457 |
|
1504 |
|
1458 |
static struct url * |
1505 |
static struct url * |
Lines 1601-1609
Link Here
|
1601 |
} |
1648 |
} |
1602 |
|
1649 |
|
1603 |
/* connect to server or proxy */ |
1650 |
/* connect to server or proxy */ |
1604 |
if ((conn = http_connect(url, purl, flags)) == NULL) |
1651 |
/* Getting connection without proxy connection */ |
|
|
1652 |
if ((conn = http_connect(url, purl, flags, 0)) == NULL) |
1605 |
goto ouch; |
1653 |
goto ouch; |
1606 |
|
1654 |
|
|
|
1655 |
/* If returning object request proxy auth, rerun the connect with proxy auth */ |
1656 |
if (conn->err == HTTP_NEED_PROXY_AUTH) { |
1657 |
if ((conn = http_connect(url, purl, flags, 1)) == NULL) |
1658 |
goto ouch; |
1659 |
} |
1660 |
|
1607 |
host = url->host; |
1661 |
host = url->host; |
1608 |
#ifdef INET6 |
1662 |
#ifdef INET6 |
1609 |
if (strchr(url->host, ':')) { |
1663 |
if (strchr(url->host, ':')) { |