View | Details | Raw Unified | Return to bug 220468 | Differences between
and this patch

Collapse All | Expand All

(-)lib/libfetch/http.c (-6 / +43 lines)
Lines 1409-1420 Link Here
1409
		return (NULL);
1409
		return (NULL);
1410
	init_http_headerbuf(&headerbuf);
1410
	init_http_headerbuf(&headerbuf);
1411
	if (strcmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) {
1411
	if (strcmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) {
1412
		http_cmd(conn, "CONNECT %s:%d HTTP/1.1",
1412
		for (int retry = 0; retry < 2; ++retry) {
1413
		    URL->host, URL->port);
1413
			if (retry > 0) {
1414
		http_cmd(conn, "Host: %s:%d",
1414
				fetch_close(conn);
1415
		    URL->host, URL->port);
1415
				conn = fetch_connect(curl->host, curl->port, af, verbose);
1416
		http_cmd(conn, "");
1416
				if (conn == NULL) {
1417
		if (http_get_reply(conn) != HTTP_OK) {
1417
					http_seterr(HTTP_NEED_PROXY_AUTH);
1418
					goto ouch;
1419
				}
1420
				clean_http_headerbuf(&headerbuf);
1421
			}
1422
			http_cmd(conn, "CONNECT %s:%d HTTP/1.1",
1423
			    URL->host, URL->port);
1424
			http_cmd(conn, "Host: %s:%d",
1425
			    URL->host, URL->port);
1426
			if (retry > 0) {
1427
				http_auth_challenges_t proxy_challenges;
1428
				http_auth_params_t aparams;
1429
				init_http_auth_challenges(&proxy_challenges);
1430
				init_http_auth_params(&aparams);
1431
				if (*purl->user || *purl->pwd) {
1432
					aparams.user = strdup(purl->user);
1433
					aparams.password = strdup(purl->pwd);
1434
				} else if ((p = getenv("HTTP_PROXY_AUTH")) != NULL &&
1435
					   *p != '\0') {
1436
					if (http_authfromenv(p, &aparams) < 0) {
1437
						http_seterr(HTTP_NEED_PROXY_AUTH);
1438
						goto ouch;
1439
					}
1440
				} else if (fetch_netrc_auth(purl) == 0) {
1441
					aparams.user = strdup(purl->user);
1442
					aparams.password = strdup(purl->pwd);
1443
				} else {
1444
					http_seterr(HTTP_NEED_PROXY_AUTH);
1445
					goto ouch;
1446
				}
1447
				http_authorize(conn, "Proxy-Authorization",
1448
					       &proxy_challenges, &aparams, purl);
1449
				clean_http_auth_params(&aparams);
1450
			}
1451
			http_cmd(conn, "");
1452
			if (http_get_reply(conn) != HTTP_NEED_PROXY_AUTH) break;
1453
		}
1454
		if (conn->err != HTTP_OK) {
1418
			http_seterr(conn->err);
1455
			http_seterr(conn->err);
1419
			goto ouch;
1456
			goto ouch;
1420
		}
1457
		}

Return to bug 220468