summaryrefslogtreecommitdiff
path: root/lib/http.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-01-08 17:58:15 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-01-17 23:56:09 +0100
commit215db086e09665ee7af9b646ad6c4d6e281001ac (patch)
tree50c74f8456df87e86de6d72e90190a3563083a1a /lib/http.c
parent0d26ab9ed3ac29da2a383d313e93df3e9f5295a2 (diff)
downloadcurl-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.c')
-rw-r--r--lib/http.c268
1 files changed, 135 insertions, 133 deletions
diff --git a/lib/http.c b/lib/http.c
index 1794f43a2..0d1d0d568 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -94,22 +94,25 @@
* Forward declarations.
*/
-static int http_getsock_do(struct connectdata *conn,
+static int http_getsock_do(struct Curl_easy *data,
+ struct connectdata *conn,
curl_socket_t *socks);
-static bool http_should_fail(struct connectdata *conn);
+static bool http_should_fail(struct Curl_easy *data);
#ifndef CURL_DISABLE_PROXY
-static CURLcode add_haproxy_protocol_header(struct connectdata *conn);
+static CURLcode add_haproxy_protocol_header(struct Curl_easy *data);
#endif
#ifdef USE_SSL
-static CURLcode https_connecting(struct connectdata *conn, bool *done);
-static int https_getsock(struct connectdata *conn,
+static CURLcode https_connecting(struct Curl_easy *data, bool *done);
+static int https_getsock(struct Curl_easy *data,
+ struct connectdata *conn,
curl_socket_t *socks);
#else
#define https_connecting(x,y) CURLE_COULDNT_CONNECT
#endif
-static CURLcode http_setup_conn(struct connectdata *conn);
+static CURLcode http_setup_conn(struct Curl_easy *data,
+ struct connectdata *conn);
/*
* HTTP handler interface.
@@ -165,19 +168,19 @@ const struct Curl_handler Curl_handler_https = {
};
#endif
-static CURLcode http_setup_conn(struct connectdata *conn)
+static CURLcode http_setup_conn(struct Curl_easy *data,
+ struct connectdata *conn)
{
/* allocate the HTTP-specific struct for the Curl_easy, only to survive
during this request */
struct HTTP *http;
- struct Curl_easy *data = conn->data;
DEBUGASSERT(data->req.p.http == NULL);
http = calloc(1, sizeof(struct HTTP));
if(!http)
return CURLE_OUT_OF_MEMORY;
- Curl_mime_initpart(&http->form, conn->data);
+ Curl_mime_initpart(&http->form, data);
data->req.p.http = http;
if(data->set.httpversion == CURL_HTTP_VERSION_3) {
@@ -205,16 +208,16 @@ static CURLcode http_setup_conn(struct connectdata *conn)
* if proxy headers are not available, then it will lookup into http header
* link list
*
- * It takes a connectdata struct as input instead of the Curl_easy simply to
- * know if this is a proxy request or not, as it then might check a different
- * header list. Provide the header prefix without colon!.
+ * It takes a connectdata struct as input to see if this is a proxy request or
+ * not, as it then might check a different header list. Provide the header
+ * prefix without colon!
*/
-char *Curl_checkProxyheaders(const struct connectdata *conn,
+char *Curl_checkProxyheaders(struct Curl_easy *data,
+ const struct connectdata *conn,
const char *thisheader)
{
struct curl_slist *head;
size_t thislen = strlen(thisheader);
- struct Curl_easy *data = conn->data;
for(head = (conn->bits.proxy && data->set.sep_headers) ?
data->set.proxyheaders : data->set.headers;
@@ -228,7 +231,7 @@ char *Curl_checkProxyheaders(const struct connectdata *conn,
}
#else
/* disabled */
-#define Curl_checkProxyheaders(x,y) NULL
+#define Curl_checkProxyheaders(x,y,z) NULL
#endif
/*
@@ -291,11 +294,11 @@ char *Curl_copy_header_value(const char *header)
*
* Returns CURLcode.
*/
-static CURLcode http_output_basic(struct connectdata *conn, bool proxy)
+static CURLcode http_output_basic(struct Curl_easy *data, bool proxy)
{
size_t size = 0;
char *authorization = NULL;
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
char **userp;
const char *user;
const char *pwd;
@@ -351,16 +354,15 @@ static CURLcode http_output_basic(struct connectdata *conn, bool proxy)
*
* Returns CURLcode.
*/
-static CURLcode http_output_bearer(struct connectdata *conn)
+static CURLcode http_output_bearer(struct Curl_easy *data)
{
char **userp;
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
userp = &data->state.aptr.userpwd;
free(*userp);
*userp = aprintf("Authorization: Bearer %s\r\n",
- conn->data->set.str[STRING_BEARER]);
+ data->set.str[STRING_BEARER]);
if(!*userp) {
result = CURLE_OUT_OF_MEMORY;
@@ -433,9 +435,9 @@ static bool pickoneauth(struct auth *pick, unsigned long mask)
* }
* }
*/
-static CURLcode http_perhapsrewind(struct connectdata *conn)
+static CURLcode http_perhapsrewind(struct Curl_easy *data,
+ struct connectdata *conn)
{
- struct Curl_easy *data = conn->data;
struct HTTP *http = data->req.p.http;
curl_off_t bytessent;
curl_off_t expectsend = -1; /* default is unknown */
@@ -565,9 +567,9 @@ static CURLcode http_perhapsrewind(struct connectdata *conn)
* picked.
*/
-CURLcode Curl_http_auth_act(struct connectdata *conn)
+CURLcode Curl_http_auth_act(struct Curl_easy *data)
{
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
bool pickhost = FALSE;
bool pickproxy = FALSE;
CURLcode result = CURLE_OK;
@@ -593,7 +595,7 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
conn->httpversion > 11) {
infof(data, "Forcing HTTP/1.1 for NTLM");
connclose(conn, "Force HTTP/1.1 connection");
- conn->data->set.httpversion = CURL_HTTP_VERSION_1_1;
+ data->set.httpversion = CURL_HTTP_VERSION_1_1;
}
}
#ifndef CURL_DISABLE_PROXY
@@ -611,7 +613,7 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
if((data->state.httpreq != HTTPREQ_GET) &&
(data->state.httpreq != HTTPREQ_HEAD) &&
!conn->bits.rewindaftersend) {
- result = http_perhapsrewind(conn);
+ result = http_perhapsrewind(data, conn);
if(result)
return result;
}
@@ -638,7 +640,7 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
data->state.authhost.done = TRUE;
}
}
- if(http_should_fail(conn)) {
+ if(http_should_fail(data)) {
failf(data, "The requested URL returned error: %d",
data->req.httpcode);
result = CURLE_HTTP_RETURNED_ERROR;
@@ -653,7 +655,8 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
* and whether or not it is to a proxy.
*/
static CURLcode
-output_auth_headers(struct connectdata *conn,
+output_auth_headers(struct Curl_easy *data,
+ struct connectdata *conn,
struct auth *authstatus,
const char *request,
const char *path,
@@ -661,7 +664,6 @@ output_auth_headers(struct connectdata *conn,
{
const char *auth = NULL;
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
#ifdef CURL_DISABLE_CRYPTO_AUTH
(void)request;
@@ -720,12 +722,12 @@ output_auth_headers(struct connectdata *conn,
if(
#ifndef CURL_DISABLE_PROXY
(proxy && conn->bits.proxy_user_passwd &&
- !Curl_checkProxyheaders(conn, "Proxy-authorization")) ||
+ !Curl_checkProxyheaders(data, conn, "Proxy-authorization")) ||
#endif
(!proxy && conn->bits.user_passwd &&
- !Curl_checkheaders(conn, "Authorization"))) {
+ !Curl_checkheaders(data, "Authorization"))) {
auth = "Basic";
- result = http_output_basic(conn, proxy);
+ result = http_output_basic(data, proxy);
if(result)
return result;
}
@@ -737,9 +739,9 @@ output_auth_headers(struct connectdata *conn,
if(authstatus->picked == CURLAUTH_BEARER) {
/* Bearer */
if((!proxy && data->set.str[STRING_BEARER] &&
- !Curl_checkheaders(conn, "Authorization:"))) {
+ !Curl_checkheaders(data, "Authorization:"))) {
auth = "Bearer";
- result = http_output_bearer(conn);
+ result = http_output_bearer(data);
if(result)
return result;
}
@@ -770,7 +772,7 @@ output_auth_headers(struct connectdata *conn,
/**
* Curl_http_output_auth() setups the authentication headers for the
* host/proxy and the correct authentication
- * method. conn->data->state.authdone is set to TRUE when authentication is
+ * method. data->state.authdone is set to TRUE when authentication is
* done.
*
* @param conn all information about the current connection
@@ -782,7 +784,8 @@ output_auth_headers(struct connectdata *conn,
* @returns CURLcode
*/
CURLcode
-Curl_http_output_auth(struct connectdata *conn,
+Curl_http_output_auth(struct Curl_easy *data,
+ struct connectdata *conn,
const char *request,
Curl_HttpReq httpreq,
const char *path,
@@ -790,7 +793,6 @@ Curl_http_output_auth(struct connectdata *conn,
up the proxy tunnel */
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
struct auth *authhost;
struct auth *authproxy;
@@ -827,7 +829,7 @@ Curl_http_output_auth(struct connectdata *conn,
/* Send proxy authentication header if needed */
if(conn->bits.httpproxy &&
(conn->bits.tunnel_proxy == (bit)proxytunnel)) {
- result = output_auth_headers(conn, authproxy, request, path, TRUE);
+ result = output_auth_headers(data, conn, authproxy, request, path, TRUE);
if(result)
return result;
}
@@ -846,7 +848,7 @@ Curl_http_output_auth(struct connectdata *conn,
!data->state.first_host ||
data->set.allow_auth_to_other_hosts ||
strcasecompare(data->state.first_host, conn->host.name)) {
- result = output_auth_headers(conn, authhost, request, path, FALSE);
+ result = output_auth_headers(data, conn, authhost, request, path, FALSE);
}
else
authhost->done = TRUE;
@@ -887,14 +889,13 @@ Curl_http_output_auth(struct connectdata *conn,
* proxy CONNECT loop.
*/
-CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
+CURLcode Curl_http_input_auth(struct Curl_easy *data, bool proxy,
const char *auth) /* the first non-space */
{
/*
* This resource requires authentication
*/
- struct Curl_easy *data = conn->data;
-
+ struct connectdata *conn = data->conn;
#ifdef USE_SPNEGO
curlnegotiate *negstate = proxy ? &conn->proxy_negotiate_state :
&conn->http_negotiate_state;
@@ -1062,14 +1063,11 @@ CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
*
* @retval TRUE communications should not continue
*/
-static bool http_should_fail(struct connectdata *conn)
+static bool http_should_fail(struct Curl_easy *data)
{
- struct Curl_easy *data;
int httpcode;
-
- DEBUGASSERT(conn);
- data = conn->data;
DEBUGASSERT(data);
+ DEBUGASSERT(data->conn);
httpcode = data->req.httpcode;
@@ -1116,10 +1114,10 @@ static bool http_should_fail(struct connectdata *conn)
** Either we're not authenticating, or we're supposed to
** be authenticating something else. This is an error.
*/
- if((httpcode == 401) && !conn->bits.user_passwd)
+ if((httpcode == 401) && !data->conn->bits.user_passwd)
return TRUE;
#ifndef CURL_DISABLE_PROXY
- if((httpcode == 407) && !conn->bits.proxy_user_passwd)
+ if((httpcode == 407) && !data->conn->bits.proxy_user_passwd)
return TRUE;
#endif
@@ -1140,8 +1138,8 @@ static size_t readmoredata(char *buffer,
size_t nitems,
void *userp)
{
- struct connectdata *conn = (struct connectdata *)userp;
- struct HTTP *http = conn->data->req.p.http;
+ struct Curl_easy *data = (struct Curl_easy *)userp;
+ struct HTTP *http = data->req.p.http;
size_t fullsize = size * nitems;
if(!http->postsize)
@@ -1149,7 +1147,7 @@ static size_t readmoredata(char *buffer,
return 0;
/* make sure that a HTTP request is never sent away chunked! */
- conn->data->req.forbidchunk = (http->sending == HTTPSEND_REQUEST)?TRUE:FALSE;
+ data->req.forbidchunk = (http->sending == HTTPSEND_REQUEST)?TRUE:FALSE;
if(http->postsize <= (curl_off_t)fullsize) {
memcpy(buffer, http->postdata, (size_t)http->postsize);
@@ -1159,8 +1157,8 @@ static size_t readmoredata(char *buffer,
/* move backup data into focus and continue on that */
http->postdata = http->backup.postdata;
http->postsize = http->backup.postsize;
- conn->data->state.fread_func = http->backup.fread_func;
- conn->data->state.in = http->backup.fread_in;
+ data->state.fread_func = http->backup.fread_func;
+ data->state.in = http->backup.fread_in;
http->sending++; /* move one step up */
@@ -1186,7 +1184,7 @@ static size_t readmoredata(char *buffer,
* Returns CURLcode
*/
CURLcode Curl_buffer_send(struct dynbuf *in,
- struct connectdata *conn,
+ struct Curl_easy *data,
/* add the number of sent bytes to this
counter */
curl_off_t *bytes_written,
@@ -1198,7 +1196,7 @@ CURLcode Curl_buffer_send(struct dynbuf *in,
CURLcode result;
char *ptr;
size_t size;
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
struct HTTP *http = data->req.p.http;
size_t sendsize;
curl_socket_t sockfd;
@@ -1274,7 +1272,7 @@ CURLcode Curl_buffer_send(struct dynbuf *in,
sendsize = size;
}
- result = Curl_write(conn, sockfd, ptr, sendsize, &amount);
+ result = Curl_write(data, sockfd, ptr, sendsize, &amount);
if(!result) {
/*
@@ -1321,7 +1319,7 @@ CURLcode Curl_buffer_send(struct dynbuf *in,
/* set the new pointers for the request-sending */
data->state.fread_func = (curl_read_callback)readmoredata;
- data->state.in = (void *)conn;
+ data->state.in = (void *)data;
http->postdata = ptr;
http->postsize = (curl_off_t)size;
@@ -1421,9 +1419,10 @@ Curl_compareheader(const char *headerline, /* line to check */
* Curl_http_connect() performs HTTP stuff to do at connect-time, called from
* the generic Curl_connect().
*/
-CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
+CURLcode Curl_http_connect(struct Curl_easy *data, bool *done)
{
CURLcode result;
+ struct connectdata *conn = data->conn;
/* We default to persistent connections. We set this already in this connect
function to make the re-use checks properly be able to check this bit. */
@@ -1446,9 +1445,9 @@ CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
/* nothing else to do except wait right now - we're not done here. */
return CURLE_OK;
- if(conn->data->set.haproxyprotocol) {
+ if(data->set.haproxyprotocol) {
/* add HAProxy PROXY protocol header */
- result = add_haproxy_protocol_header(conn);
+ result = add_haproxy_protocol_header(data);
if(result)
return result;
}
@@ -1456,7 +1455,7 @@ CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
if(conn->given->protocol & CURLPROTO_HTTPS) {
/* perform SSL initialization */
- result = https_connecting(conn, done);
+ result = https_connecting(data, done);
if(result)
return result;
}
@@ -1469,24 +1468,27 @@ CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
/* this returns the socket to wait for in the DO and DOING state for the multi
interface and then we're always _sending_ a request and thus we wait for
the single socket to become writable only */
-static int http_getsock_do(struct connectdata *conn,
+static int http_getsock_do(struct Curl_easy *data,
+ struct connectdata *conn,
curl_socket_t *socks)
{
/* write mode */
+ (void)data;
socks[0] = conn->sock[FIRSTSOCKET];
return GETSOCK_WRITESOCK(0);
}
#ifndef CURL_DISABLE_PROXY
-static CURLcode add_haproxy_protocol_header(struct connectdata *conn)
+static CURLcode add_haproxy_protocol_header(struct Curl_easy *data)
{
char proxy_header[128];
struct dynbuf req;
CURLcode result;
char tcp_version[5];
+ DEBUGASSERT(data->conn);
/* Emit the correct prefix for IPv6 */
- if(conn->bits.ipv6) {
+ if(data->conn->bits.ipv6) {
strcpy(tcp_version, "TCP6");
}
else {
@@ -1497,10 +1499,10 @@ static CURLcode add_haproxy_protocol_header(struct connectdata *conn)
sizeof(proxy_header),
"PROXY %s %s %s %li %li\r\n",
tcp_version,
- conn->data->info.conn_local_ip,
- conn->data->info.conn_primary_ip,
- conn->data->info.conn_local_port,
- conn->data->info.conn_primary_port);
+ data->info.conn_local_ip,
+ data->info.conn_primary_ip,
+ data->info.conn_local_port,
+ data->info.conn_primary_port);
Curl_dyn_init(&req, DYN_HAXPROXY);
@@ -1508,7 +1510,7 @@ static CURLcode add_haproxy_protocol_header(struct connectdata *conn)
if(result)
return result;
- result = Curl_buffer_send(&req, conn, &conn->data->info.request_size,
+ result = Curl_buffer_send(&req, data, &data->info.request_size,
0, FIRSTSOCKET);
return result;
@@ -1516,10 +1518,11 @@ static CURLcode add_haproxy_protocol_header(struct connectdata *conn)
#endif
#ifdef USE_SSL
-static CURLcode https_connecting(struct connectdata *conn, bool *done)
+static CURLcode https_connecting(struct Curl_easy *data, bool *done)
{
CURLcode result;
- DEBUGASSERT((conn) && (conn->handler->flags & PROTOPT_SSL));
+ struct connectdata *conn = data->conn;
+ DEBUGASSERT((data) && (data->conn->handler->flags & PROTOPT_SSL));
#ifdef ENABLE_QUIC
if(conn->transport == TRNSPRT_QUIC) {
@@ -1536,9 +1539,11 @@ static CURLcode https_connecting(struct connectdata *conn, bool *done)
return result;
}
-static int https_getsock(struct connectdata *conn,
+static int https_getsock(struct Curl_easy *data,
+ struct connectdata *conn,
curl_socket_t *socks)
{
+ (void)data;
if(conn->handler->flags & PROTOPT_SSL)
return Curl_ssl_getsock(conn, socks);
return GETSOCK_BLANK;
@@ -1550,10 +1555,10 @@ static int https_getsock(struct connectdata *conn,
* performed.
*/
-CURLcode Curl_http_done(struct connectdata *conn,
+CURLcode Curl_http_done(struct Curl_easy *data,
CURLcode status, bool premature)
{
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
struct HTTP *http = data->req.p.http;
/* Clear multipass flag. If authentication isn't done yet, then it will get
@@ -1653,7 +1658,7 @@ static CURLcode expect100(struct Curl_easy *data,
/* if not doing HTTP 1.0 or version 2, or disabled explicitly, we add an
Expect: 100-continue to the headers which actually speeds up post
operations (as there is one packet coming back from the web server) */
- const char *ptr = Curl_checkheaders(conn, "Expect");
+ const char *ptr = Curl_checkheaders(data, "Expect");
if(ptr) {
data->state.expect100header =
Curl_compareheader(ptr, "Expect:", "100-continue");
@@ -1719,7 +1724,7 @@ CURLcode Curl_http_compile_trailers(struct curl_slist *trailers,
return result;
}
-CURLcode Curl_add_custom_headers(struct connectdata *conn,
+CURLcode Curl_add_custom_headers(struct Curl_easy *data,
bool is_connect,
#ifndef USE_HYPER
struct dynbuf *req
@@ -1728,11 +1733,11 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
#endif
)
{
+ struct connectdata *conn = data->conn;
char *ptr;
struct curl_slist *h[2];
struct curl_slist *headers;
int numlists = 1; /* by default */
- struct Curl_easy *data = conn->data;
int i;
#ifndef CURL_DISABLE_PROXY
@@ -1876,15 +1881,14 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
}
#ifndef CURL_DISABLE_PARSEDATE
-CURLcode Curl_add_timecondition(const struct connectdata *conn,
+CURLcode Curl_add_timecondition(struct Curl_easy *data,
#ifndef USE_HYPER
- struct dynbuf *req
+ struct dynbuf *req
#else
- void *req
+ void *req
#endif
)
{
- struct Curl_easy *data = conn->data;
const struct tm *tm;
struct tm keeptime;
CURLcode result;
@@ -1917,7 +1921,7 @@ CURLcode Curl_add_timecondition(const struct connectdata *conn,
break;
}
- if(Curl_checkheaders(conn, condp)) {
+ if(Curl_checkheaders(data, condp)) {
/* A custom header was specified; it will be sent instead. */
return CURLE_OK;
}
@@ -2000,13 +2004,13 @@ void Curl_http_method(struct Curl_easy *data, struct connectdata *conn,
*reqp = httpreq;
}
-CURLcode Curl_http_useragent(struct Curl_easy *data, struct connectdata *conn)
+CURLcode Curl_http_useragent(struct Curl_easy *data)
{
/* The User-Agent string might have been allocated in url.c already, because
it might have been used in the proxy connect, but if we have got a header
with the user-agent string specified, we erase the previously made string
here. */
- if(Curl_checkheaders(conn, "User-Agent")) {
+ if(Curl_checkheaders(data, "User-Agent")) {
free(data->state.aptr.uagent);
data->state.aptr.uagent = NULL;
}
@@ -2029,7 +2033,7 @@ CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn)
}
Curl_safefree(data->state.aptr.host);
- ptr = Curl_checkheaders(conn, "Host");
+ ptr = Curl_checkheaders(data, "Host");
if(ptr && (!data->state.this_is_a_follow ||
strcasecompare(data->state.first_host, conn->host.name))) {
#if !defined(CURL_DISABLE_COOKIES)
@@ -2245,7 +2249,7 @@ CURLcode Curl_http_body(struct Curl_easy *data, struct connectdata *conn,
#ifndef CURL_DISABLE_MIME
if(http->sendit) {
- const char *cthdr = Curl_checkheaders(conn, "Content-Type");
+ const char *cthdr = Curl_checkheaders(data, "Content-Type");
/* Read and seek body only. */
http->sendit->flags |= MIME_BODY_ONLY;
@@ -2270,7 +2274,7 @@ CURLcode Curl_http_body(struct Curl_easy *data, struct connectdata *conn,
}
#endif
- ptr = Curl_checkheaders(conn, "Transfer-Encoding");
+ ptr = Curl_checkheaders(data, "Transfer-Encoding");
if(ptr) {
/* Some kind of TE is requested, check if 'chunked' is chosen */
data->req.upload_chunky =
@@ -2331,7 +2335,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
http->postsize = data->state.infilesize;
if((http->postsize != -1) && !data->req.upload_chunky &&
- (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length"))) {
+ (conn->bits.authneg || !Curl_checkheaders(data, "Content-Length"))) {
/* only add Content-Length if not uploading chunked */
result = Curl_dyn_addf(r, "Content-Length: %" CURL_FORMAT_CURL_OFF_T
"\r\n", http->postsize);
@@ -2354,7 +2358,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
Curl_pgrsSetUploadSize(data, http->postsize);
/* this sends the buffer and frees all the buffer resources */
- result = Curl_buffer_send(r, conn, &data->info.request_size, 0,
+ result = Curl_buffer_send(r, data, &data->info.request_size, 0,
FIRSTSOCKET);
if(result)
failf(data, "Failed sending PUT request");
@@ -2375,7 +2379,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
if(result)
return result;
- result = Curl_buffer_send(r, conn, &data->info.request_size, 0,
+ result = Curl_buffer_send(r, data, &data->info.request_size, 0,
FIRSTSOCKET);
if(result)
failf(data, "Failed sending POST request");
@@ -2391,7 +2395,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
we don't upload data chunked, as RFC2616 forbids us to set both
kinds of headers (Transfer-Encoding: chunked and Content-Length) */
if(http->postsize != -1 && !data->req.upload_chunky &&
- (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length"))) {
+ (conn->bits.authneg || !Curl_checkheaders(data, "Content-Length"))) {
/* we allow replacing this header if not during auth negotiation,
although it isn't very wise to actually set your own */
result = Curl_dyn_addf(r,
@@ -2418,7 +2422,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
the somewhat bigger ones we allow the app to disable it. Just make
sure that the expect100header is always set to the preferred value
here. */
- ptr = Curl_checkheaders(conn, "Expect");
+ ptr = Curl_checkheaders(data, "Expect");
if(ptr) {
data->state.expect100header =
Curl_compareheader(ptr, "Expect:", "100-continue");
@@ -2445,7 +2449,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
http->sending = HTTPSEND_BODY;
/* this sends the buffer and frees all the buffer resources */
- result = Curl_buffer_send(r, conn, &data->info.request_size, 0,
+ result = Curl_buffer_send(r, data, &data->info.request_size, 0,
FIRSTSOCKET);
if(result)
failf(data, "Failed sending POST request");
@@ -2471,7 +2475,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
we don't upload data chunked, as RFC2616 forbids us to set both
kinds of headers (Transfer-Encoding: chunked and Content-Length) */
if((http->postsize != -1) && !data->req.upload_chunky &&
- (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length"))) {
+ (conn->bits.authneg || !Curl_checkheaders(data, "Content-Length"))) {
/* we allow replacing this header if not during auth negotiation,
although it isn't very wise to actually set your own */
result = Curl_dyn_addf(r, "Content-Length: %" CURL_FORMAT_CURL_OFF_T
@@ -2480,7 +2484,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
return result;
}
- if(!Curl_checkheaders(conn, "Content-Type")) {
+ if(!Curl_checkheaders(data, "Content-Type")) {
result = Curl_dyn_add(r, "Content-Type: application/"
"x-www-form-urlencoded\r\n");
if(result)
@@ -2491,7 +2495,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
the somewhat bigger ones we allow the app to disable it. Just make
sure that the expect100header is always set to the preferred value
here. */
- ptr = Curl_checkheaders(conn, "Expect");
+ ptr = Curl_checkheaders(data, "Expect");
if(ptr) {
data->state.expect100header =
Curl_compareheader(ptr, "Expect:", "100-continue");
@@ -2565,7 +2569,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
http->sending = HTTPSEND_BODY;
data->state.fread_func = (curl_read_callback)readmoredata;
- data->state.in = (void *)conn;
+ data->state.in = (void *)data;
/* set the upload size to the progress meter */
Curl_pgrsSetUploadSize(data, http->postsize);
@@ -2604,7 +2608,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
}
}
/* issue the request */
- result = Curl_buffer_send(r, conn, &data->info.request_size,
+ result = Curl_buffer_send(r, data, &data->info.request_size,
(size_t)included_body, FIRSTSOCKET);
if(result)
@@ -2620,7 +2624,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
return result;
/* issue the request */
- result = Curl_buffer_send(r, conn, &data->info.request_size, 0,
+ result = Curl_buffer_send(r, data, &data->info.request_size, 0,
FIRSTSOCKET);
if(result)
@@ -2640,7 +2644,7 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
{
CURLcode result = CURLE_OK;
char *addcookies = NULL;
- if(data->set.str[STRING_COOKIE] && !Curl_checkheaders(conn, "Cookie"))
+ if(data->set.str[STRING_COOKIE] && !Curl_checkheaders(data, "Cookie"))
addcookies = data->set.str[STRING_COOKIE];
if(data->cookies || addcookies) {
@@ -2697,7 +2701,6 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
#endif
CURLcode Curl_http_range(struct Curl_easy *data,
- struct connectdata *conn,
Curl_HttpReq httpreq)
{
if(data->state.use_range) {
@@ -2707,14 +2710,14 @@ CURLcode Curl_http_range(struct Curl_easy *data,
* ones if any such are specified.
*/
if(((httpreq == HTTPREQ_GET) || (httpreq == HTTPREQ_HEAD)) &&
- !Curl_checkheaders(conn, "Range")) {
+ !Curl_checkheaders(data, "Range")) {
/* if a line like this was already allocated, free the previous one */
free(data->state.aptr.rangeline);
data->state.aptr.rangeline = aprintf("Range: bytes=%s\r\n",
data->state.range);
}
else if((httpreq == HTTPREQ_POST || httpreq == HTTPREQ_PUT) &&
- !Curl_checkheaders(conn, "Content-Range")) {
+ !Curl_checkheaders(data, "Content-Range")) {
/* if a line like this was already allocated, free the previous one */
free(data->state.aptr.rangeline);
@@ -2902,9 +2905,9 @@ CURLcode Curl_http_firstwrite(struct Curl_easy *data,
* request is to be performed. This creates and sends a properly constructed
* HTTP request.
*/
-CURLcode Curl_http(struct connectdata *conn, bool *done)
+CURLcode Curl_http(struct Curl_easy *data, bool *done)
{
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
CURLcode result = CURLE_OK;
struct HTTP *http;
Curl_HttpReq httpreq;
@@ -2927,7 +2930,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
case CURL_HTTP_VERSION_2:
conn->httpversion = 20; /* we know we're on HTTP/2 now */
- result = Curl_http2_switched(conn, NULL, 0);
+ result = Curl_http2_switched(data, NULL, 0);
if(result)
return result;
break;
@@ -2937,8 +2940,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
default:
/* Check if user wants to use HTTP/2 with clear TCP*/
#ifdef USE_NGHTTP2
- if(conn->data->set.httpversion ==
- CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE) {
+ if(data->set.httpversion == CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE) {
#ifndef CURL_DISABLE_PROXY
if(conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
/* We don't support HTTP/2 proxies yet. Also it's debatable
@@ -2950,7 +2952,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
DEBUGF(infof(data, "HTTP/2 over clean TCP\n"));
conn->httpversion = 20;
- result = Curl_http2_switched(conn, NULL, 0);
+ result = Curl_http2_switched(data, NULL, 0);
if(result)
return result;
}
@@ -2960,7 +2962,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
else {
/* prepare for a http2 request */
- result = Curl_http2_setup(conn);
+ result = Curl_http2_setup(data, conn);
if(result)
return result;
}
@@ -2972,7 +2974,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(result)
return result;
- result = Curl_http_useragent(data, conn);
+ result = Curl_http_useragent(data);
if(result)
return result;
@@ -2986,7 +2988,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(!pq)
return CURLE_OUT_OF_MEMORY;
}
- result = Curl_http_output_auth(conn, request, httpreq,
+ result = Curl_http_output_auth(data, conn, request, httpreq,
(pq ? pq : data->state.up.path), FALSE);
free(pq);
if(result)
@@ -2994,13 +2996,13 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
Curl_safefree(data->state.aptr.ref);
- if(data->change.referer && !Curl_checkheaders(conn, "Referer")) {
+ if(data->change.referer && !Curl_checkheaders(data, "Referer")) {
data->state.aptr.ref = aprintf("Referer: %s\r\n", data->change.referer);
if(!data->state.aptr.ref)
return CURLE_OUT_OF_MEMORY;
}
- if(!Curl_checkheaders(conn, "Accept-Encoding") &&
+ if(!Curl_checkheaders(data, "Accept-Encoding") &&
data->set.str[STRING_ENCODING]) {
Curl_safefree(data->state.aptr.accept_encoding);
data->state.aptr.accept_encoding =
@@ -3016,14 +3018,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
#ifdef HAVE_LIBZ
/* we only consider transfer-encoding magic if libz support is built-in */
- if(!Curl_checkheaders(conn, "TE") &&
+ if(!Curl_checkheaders(data, "TE") &&
data->set.http_transfer_encoding) {
/* When we are to insert a TE: header in the request, we must also insert
TE in a Connection: header, so we need to merge the custom provided
Connection: header and prevent the original to get sent. Note that if
the user has inserted his/her own TE: header we don't do this magic
but then assume that the user will handle it all! */
- char *cptr = Curl_checkheaders(conn, "Connection");
+ char *cptr = Curl_checkheaders(data, "Connection");
#define TE_HEADER "TE: gzip\r\n"
Curl_safefree(data->state.aptr.te);
@@ -3048,13 +3050,13 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(result)
return result;
- p_accept = Curl_checkheaders(conn, "Accept")?NULL:"Accept: */*\r\n";
+ p_accept = Curl_checkheaders(data, "Accept")?NULL:"Accept: */*\r\n";
result = Curl_http_resume(data, conn, httpreq);
if(result)
return result;
- result = Curl_http_range(data, conn, httpreq);
+ result = Curl_http_range(data, httpreq);
if(result)
return result;
@@ -3074,7 +3076,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
#ifndef CURL_DISABLE_ALTSVC
- if(conn->bits.altused && !Curl_checkheaders(conn, "Alt-Used")) {
+ if(conn->bits.altused && !Curl_checkheaders(data, "Alt-Used")) {
altused = aprintf("Alt-Used: %s:%d\r\n",
conn->conn_to_host.name, conn->conn_to_port);
if(!altused) {
@@ -3121,7 +3123,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
#ifndef CURL_DISABLE_PROXY
(conn->bits.httpproxy &&
!conn->bits.tunnel_proxy &&
- !Curl_checkProxyheaders(conn, "Proxy-Connection"))?
+ !Curl_checkProxyheaders(data, conn, "Proxy-Connection"))?
"Proxy-Connection: Keep-Alive\r\n":"",
#else
"",
@@ -3155,9 +3157,9 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
result = Curl_http_cookies(data, conn, &req);
if(!result)
- result = Curl_add_timecondition(conn, &req);
+ result = Curl_add_timecondition(data, &req);
if(!result)
- result = Curl_add_custom_headers(conn, FALSE, &req);
+ result = Curl_add_custom_headers(data, FALSE, &req);
if(!result) {
http->postdata = NULL; /* nothing to post at this point */
@@ -3515,7 +3517,7 @@ CURLcode Curl_http_header(struct Curl_easy *data, 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);
@@ -3560,7 +3562,7 @@ CURLcode Curl_http_header(struct Curl_easy *data, struct connectdata *conn,
/* some cases of POST and PUT etc needs to rewind the data
stream at this point */
- result = http_perhapsrewind(conn);
+ result = http_perhapsrewind(data, conn);
if(result)
return result;
}
@@ -3849,7 +3851,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
/* switch to http2 now. The bytes after response headers
are also processed here, otherwise they are lost. */
- result = Curl_http2_switched(conn, k->str, *nread);
+ result = Curl_http2_switched(data, k->str, *nread);
if(result)
return result;
*nread = 0;
@@ -3923,7 +3925,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
writetype |= CLIENTWRITE_BODY;
headerlen = Curl_dyn_len(&data->state.headerb);
- result = Curl_client_write(conn, writetype,
+ result = Curl_client_write(data, writetype,
Curl_dyn_ptr(&data->state.headerb),
headerlen);
if(result)
@@ -3936,7 +3938,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
* When all the headers have been parsed, see if we should give
* up and return an error.
*/
- if(http_should_fail(conn)) {
+ if(http_should_fail(data)) {
failf(data, "The requested URL returned error: %d",
k->httpcode);
return CURLE_HTTP_RETURNED_ERROR;
@@ -3948,7 +3950,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
/* Curl_http_auth_act() checks what authentication methods
* that are available and decides which one (if any) to
* use. It will set 'newurl' if an auth method was picked. */
- result = Curl_http_auth_act(conn);
+ result = Curl_http_auth_act(data);
if(result)
return result;
@@ -3986,8 +3988,8 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
infof(data, "Got 417 while waiting for a 100\n");
data->state.disableexpect = TRUE;
DEBUGASSERT(!data->req.newurl);
- data->req.newurl = strdup(conn->data->change.url);
- Curl_done_sending(conn, k);
+ data->req.newurl = strdup(data->change.url);
+ Curl_done_sending(data, k);
}
else if(data->set.http_keep_sending_on_error) {
infof(data, "HTTP error before end of send, keep sending\n");
@@ -3999,7 +4001,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
else {
infof(data, "HTTP error before end of send, stop sending\n");
streamclose(conn, "Stop sending data before everything sent");
- result = Curl_done_sending(conn, k);
+ result = Curl_done_sending(data, k);
if(result)
return result;
k->upload_done = TRUE;
@@ -4237,7 +4239,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
Curl_debug(data, CURLINFO_HEADER_IN, headp,
Curl_dyn_len(&data->state.headerb));
- result = Curl_client_write(conn, writetype, headp,
+ result = Curl_client_write(data, writetype, headp,
Curl_dyn_len(&data->state.headerb));
if(result)
return result;