diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-01-08 17:58:15 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-01-17 23:56:09 +0100 |
commit | 215db086e09665ee7af9b646ad6c4d6e281001ac (patch) | |
tree | 50c74f8456df87e86de6d72e90190a3563083a1a /lib/http_proxy.c | |
parent | 0d26ab9ed3ac29da2a383d313e93df3e9f5295a2 (diff) | |
download | curl-215db086e09665ee7af9b646ad6c4d6e281001ac.tar.gz |
lib: pass in 'struct Curl_easy *' to most functions
... in most cases instead of 'struct connectdata *' but in some cases in
addition to.
- We mostly operate on transfers and not connections.
- We need the transfer handle to log, store data and more. Everything in
libcurl is driven by a transfer (the CURL * in the public API).
- This work clarifies and separates the transfers from the connections
better.
- We should avoid "conn->data". Since individual connections can be used
by many transfers when multiplexing, making sure that conn->data
points to the current and correct transfer at all times is difficult
and has been notoriously error-prone over the years. The goal is to
ultimately remove the conn->data pointer for this reason.
Closes #6425
Diffstat (limited to 'lib/http_proxy.c')
-rw-r--r-- | lib/http_proxy.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/http_proxy.c b/lib/http_proxy.c index 2e0c8d35f..8163c9694 100644 --- a/lib/http_proxy.c +++ b/lib/http_proxy.c @@ -184,7 +184,8 @@ static void connect_done(struct connectdata *conn) infof(conn->data, "CONNECT phase completed!\n"); } -static CURLcode CONNECT_host(struct connectdata *conn, +static CURLcode CONNECT_host(struct Curl_easy *data, + struct connectdata *conn, const char *hostname, int remote_port, char **connecthostp, @@ -203,7 +204,7 @@ static CURLcode CONNECT_host(struct connectdata *conn, if(!hostheader) return CURLE_OUT_OF_MEMORY; - if(!Curl_checkProxyheaders(conn, "Host")) { + if(!Curl_checkProxyheaders(data, conn, "Host")) { host = aprintf("Host: %s\r\n", hostheader); if(!host) { free(hostheader); @@ -258,12 +259,13 @@ static CURLcode CONNECT(struct connectdata *conn, /* initialize a dynamic send-buffer */ Curl_dyn_init(&req, DYN_HTTP_REQUEST); - result = CONNECT_host(conn, hostname, remote_port, &hostheader, &host); + result = CONNECT_host(data, conn, + hostname, remote_port, &hostheader, &host); if(result) return result; /* Setup the proxy-authorization header, if any */ - result = Curl_http_output_auth(conn, "CONNECT", HTTPREQ_GET, + result = Curl_http_output_auth(data, conn, "CONNECT", HTTPREQ_GET, hostheader, TRUE); if(!result) { @@ -272,10 +274,10 @@ static CURLcode CONNECT(struct connectdata *conn, const char *httpv = (conn->http_proxy.proxytype == CURLPROXY_HTTP_1_0) ? "1.0" : "1.1"; - if(!Curl_checkProxyheaders(conn, "Proxy-Connection")) + if(!Curl_checkProxyheaders(data, conn, "Proxy-Connection")) proxyconn = "Proxy-Connection: Keep-Alive\r\n"; - if(!Curl_checkProxyheaders(conn, "User-Agent") && + if(!Curl_checkProxyheaders(data, conn, "User-Agent") && data->set.str[STRING_USERAGENT]) useragent = data->state.aptr.uagent; @@ -295,7 +297,7 @@ static CURLcode CONNECT(struct connectdata *conn, proxyconn); if(!result) - result = Curl_add_custom_headers(conn, TRUE, &req); + result = Curl_add_custom_headers(data, TRUE, &req); if(!result) /* CRLF terminate the request */ @@ -304,7 +306,7 @@ static CURLcode CONNECT(struct connectdata *conn, if(!result) { /* Send the connect request to the proxy */ /* BLOCKING */ - result = Curl_buffer_send(&req, conn, &data->info.request_size, 0, + result = Curl_buffer_send(&req, data, &data->info.request_size, 0, sockindex); } if(result) @@ -340,7 +342,7 @@ static CURLcode CONNECT(struct connectdata *conn, /* Read one byte at a time to avoid a race condition. Wait at most one second before looping to ensure continuous pgrsUpdates. */ - result = Curl_read(conn, tunnelsocket, &byte, 1, &gotbytes); + result = Curl_read(data, tunnelsocket, &byte, 1, &gotbytes); if(result == CURLE_AGAIN) /* socket buffer drained, return */ return CURLE_OK; @@ -428,7 +430,7 @@ static CURLcode CONNECT(struct connectdata *conn, if(data->set.include_header) writetype |= CLIENTWRITE_BODY; - result = Curl_client_write(conn, writetype, linep, perline); + result = Curl_client_write(data, writetype, linep, perline); if(result) return result; } @@ -508,7 +510,7 @@ static CURLcode CONNECT(struct connectdata *conn, if(!auth) return CURLE_OUT_OF_MEMORY; - result = Curl_http_input_auth(conn, proxy, auth); + result = Curl_http_input_auth(data, proxy, auth); free(auth); @@ -567,7 +569,7 @@ static CURLcode CONNECT(struct connectdata *conn, if(data->info.httpproxycode/100 != 2) { /* Deal with the possibly already received authenticate headers. 'newurl' is set to a new URL if we must loop. */ - result = Curl_http_auth_act(conn); + result = Curl_http_auth_act(data); if(result) return result; @@ -580,7 +582,7 @@ static CURLcode CONNECT(struct connectdata *conn, if(s->close_connection && data->req.newurl) { /* Connection closed by server. Don't use it anymore */ - Curl_closesocket(conn, conn->sock[sockindex]); + Curl_closesocket(data, conn, conn->sock[sockindex]); conn->sock[sockindex] = CURL_SOCKET_BAD; break; } @@ -606,7 +608,7 @@ static CURLcode CONNECT(struct connectdata *conn, data->req.newurl = NULL; /* failure, close this connection to avoid re-use */ streamclose(conn, "proxy CONNECT failure"); - Curl_closesocket(conn, conn->sock[sockindex]); + Curl_closesocket(data, conn, conn->sock[sockindex]); conn->sock[sockindex] = CURL_SOCKET_BAD; } @@ -733,7 +735,8 @@ static CURLcode CONNECT(struct connectdata *conn, goto error; } - result = CONNECT_host(conn, hostname, remote_port, &hostheader, &host); + result = CONNECT_host(data, conn, hostname, remote_port, + &hostheader, &host); if(result) goto error; @@ -743,7 +746,7 @@ static CURLcode CONNECT(struct connectdata *conn, result = CURLE_OUT_OF_MEMORY; } /* Setup the proxy-authorization header, if any */ - result = Curl_http_output_auth(conn, "CONNECT", HTTPREQ_GET, + result = Curl_http_output_auth(data, conn, "CONNECT", HTTPREQ_GET, hostheader, TRUE); if(result) goto error; @@ -776,7 +779,7 @@ static CURLcode CONNECT(struct connectdata *conn, Curl_hyper_header(data, headers, data->state.aptr.uagent)) goto error; - if(!Curl_checkProxyheaders(conn, "Proxy-Connection") && + if(!Curl_checkProxyheaders(data, conn, "Proxy-Connection") && Curl_hyper_header(data, headers, "Proxy-Connection: Keep-Alive")) goto error; |