mirror of
https://github.com/moparisthebest/curl
synced 2025-03-11 07:39:50 -04:00
http-proxy: use a dedicated CONNECT response buffer
To make it suitably independent of the receive buffer and its flexible size.
This commit is contained in:
parent
40a074f255
commit
0cab3a394a
@ -135,16 +135,12 @@ CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
#define CONNECT_BUFFER_SIZE 16384
|
||||||
* Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
|
|
||||||
* function will issue the necessary commands to get a seamless tunnel through
|
|
||||||
* this proxy. After that, the socket can be used just as a normal socket.
|
|
||||||
*/
|
|
||||||
|
|
||||||
CURLcode Curl_proxyCONNECT(struct connectdata *conn,
|
static CURLcode CONNECT(struct connectdata *conn,
|
||||||
int sockindex,
|
int sockindex,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
int remote_port)
|
int remote_port)
|
||||||
{
|
{
|
||||||
int subversion=0;
|
int subversion=0;
|
||||||
struct Curl_easy *data=conn->data;
|
struct Curl_easy *data=conn->data;
|
||||||
@ -299,17 +295,17 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
char *line_start;
|
char *line_start;
|
||||||
|
|
||||||
ptr = data->state.buffer;
|
ptr = conn->connect_buffer;
|
||||||
line_start = ptr;
|
line_start = ptr;
|
||||||
|
|
||||||
nread = 0;
|
nread = 0;
|
||||||
perline = 0;
|
perline = 0;
|
||||||
|
|
||||||
while(nread < BUFSIZE && keepon && !error) {
|
while(nread < (size_t)CONNECT_BUFFER_SIZE && keepon && !error) {
|
||||||
if(Curl_pgrsUpdate(conn))
|
if(Curl_pgrsUpdate(conn))
|
||||||
return CURLE_ABORTED_BY_CALLBACK;
|
return CURLE_ABORTED_BY_CALLBACK;
|
||||||
|
|
||||||
if(ptr >= &data->state.buffer[BUFSIZE]) {
|
if(ptr >= &conn->connect_buffer[CONNECT_BUFFER_SIZE]) {
|
||||||
failf(data, "CONNECT response too large!");
|
failf(data, "CONNECT response too large!");
|
||||||
return CURLE_RECV_ERROR;
|
return CURLE_RECV_ERROR;
|
||||||
}
|
}
|
||||||
@ -358,7 +354,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
|
|||||||
/* This means we are currently ignoring a response-body */
|
/* This means we are currently ignoring a response-body */
|
||||||
|
|
||||||
nread = 0; /* make next read start over in the read buffer */
|
nread = 0; /* make next read start over in the read buffer */
|
||||||
ptr = data->state.buffer;
|
ptr = conn->connect_buffer;
|
||||||
if(cl) {
|
if(cl) {
|
||||||
/* A Content-Length based body: simply count down the counter
|
/* A Content-Length based body: simply count down the counter
|
||||||
and make sure to break out of the loop when we're done! */
|
and make sure to break out of the loop when we're done! */
|
||||||
@ -430,7 +426,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
|
|||||||
/* end of response-headers from the proxy */
|
/* end of response-headers from the proxy */
|
||||||
nread = 0; /* make next read start over in the read
|
nread = 0; /* make next read start over in the read
|
||||||
buffer */
|
buffer */
|
||||||
ptr = data->state.buffer;
|
ptr = conn->connect_buffer;
|
||||||
if((407 == k->httpcode) && !data->state.authproblem) {
|
if((407 == k->httpcode) && !data->state.authproblem) {
|
||||||
/* If we get a 407 response code with content length
|
/* If we get a 407 response code with content length
|
||||||
when we have no auth problem, we must ignore the
|
when we have no auth problem, we must ignore the
|
||||||
@ -543,7 +539,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
perline = 0; /* line starts over here */
|
perline = 0; /* line starts over here */
|
||||||
ptr = data->state.buffer;
|
ptr = conn->connect_buffer;
|
||||||
line_start = ptr;
|
line_start = ptr;
|
||||||
} /* while there's buffer left and loop is requested */
|
} /* while there's buffer left and loop is requested */
|
||||||
|
|
||||||
@ -628,4 +624,33 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
|
|||||||
document request */
|
document request */
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
|
||||||
|
* function will issue the necessary commands to get a seamless tunnel through
|
||||||
|
* this proxy. After that, the socket can be used just as a normal socket.
|
||||||
|
*/
|
||||||
|
|
||||||
|
CURLcode Curl_proxyCONNECT(struct connectdata *conn,
|
||||||
|
int sockindex,
|
||||||
|
const char *hostname,
|
||||||
|
int remote_port)
|
||||||
|
{
|
||||||
|
CURLcode result;
|
||||||
|
if(TUNNEL_INIT == conn->tunnel_state[sockindex]) {
|
||||||
|
if(!conn->connect_buffer) {
|
||||||
|
conn->connect_buffer = malloc(CONNECT_BUFFER_SIZE);
|
||||||
|
if(!conn->connect_buffer)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = CONNECT(conn, sockindex, hostname, remote_port);
|
||||||
|
|
||||||
|
if(result || (TUNNEL_COMPLETE == conn->tunnel_state[sockindex]))
|
||||||
|
Curl_safefree(conn->connect_buffer);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* CURL_DISABLE_PROXY */
|
#endif /* CURL_DISABLE_PROXY */
|
||||||
|
@ -2997,6 +2997,7 @@ static void conn_free(struct connectdata *conn)
|
|||||||
Curl_safefree(conn->http_proxy.host.rawalloc); /* http proxy name buffer */
|
Curl_safefree(conn->http_proxy.host.rawalloc); /* http proxy name buffer */
|
||||||
Curl_safefree(conn->socks_proxy.host.rawalloc); /* socks proxy name buffer */
|
Curl_safefree(conn->socks_proxy.host.rawalloc); /* socks proxy name buffer */
|
||||||
Curl_safefree(conn->master_buffer);
|
Curl_safefree(conn->master_buffer);
|
||||||
|
Curl_safefree(conn->connect_buffer);
|
||||||
|
|
||||||
conn_reset_all_postponed_data(conn);
|
conn_reset_all_postponed_data(conn);
|
||||||
|
|
||||||
|
@ -1144,6 +1144,7 @@ struct connectdata {
|
|||||||
struct connectbundle *bundle; /* The bundle we are member of */
|
struct connectbundle *bundle; /* The bundle we are member of */
|
||||||
|
|
||||||
int negnpn; /* APLN or NPN TLS negotiated protocol, CURL_HTTP_VERSION* */
|
int negnpn; /* APLN or NPN TLS negotiated protocol, CURL_HTTP_VERSION* */
|
||||||
|
char *connect_buffer; /* for CONNECT business */
|
||||||
|
|
||||||
#ifdef USE_UNIX_SOCKETS
|
#ifdef USE_UNIX_SOCKETS
|
||||||
char *unix_domain_socket;
|
char *unix_domain_socket;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user