1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

http_proxy: simplify CONNECT response reading

Since it now reads responses one byte a time, a loop could be removed
and it is no longer limited to get the whole response within 16K, it is
now instead only limited to 16K maximum header line lengths.
This commit is contained in:
Daniel Stenberg 2016-11-30 00:31:23 +01:00
parent 3b77aa6b28
commit 74595b223d
2 changed files with 147 additions and 174 deletions

View File

@ -18,7 +18,6 @@ problems may have been fixed or changed somewhat since this was written!
1.4 multipart formposts file name encoding 1.4 multipart formposts file name encoding
1.5 Expect-100 meets 417 1.5 Expect-100 meets 417
1.6 Unnecessary close when 401 received waiting for 100 1.6 Unnecessary close when 401 received waiting for 100
1.7 CONNECT response larger than 16KB
1.8 DNS timing is wrong for HTTP redirects 1.8 DNS timing is wrong for HTTP redirects
1.9 HTTP/2 frames while in the connection pool kill reuse 1.9 HTTP/2 frames while in the connection pool kill reuse
1.10 Strips trailing dot from host name 1.10 Strips trailing dot from host name
@ -144,13 +143,6 @@ problems may have been fixed or changed somewhat since this was written!
waiting for the the 100-continue response. waiting for the the 100-continue response.
https://curl.haxx.se/mail/lib-2008-08/0462.html https://curl.haxx.se/mail/lib-2008-08/0462.html
1.7 CONNECT response larger than 16KB
If a CONNECT response-headers are larger than BUFSIZE (16KB) when the
connection is meant to be kept alive (like for NTLM proxy auth), the function
will return prematurely and will confuse the rest of the HTTP protocol
code. This should be very rare.
1.8 DNS timing is wrong for HTTP redirects 1.8 DNS timing is wrong for HTTP redirects
When extracting timing information after HTTP redirects, only the last When extracting timing information after HTTP redirects, only the last

View File

@ -351,14 +351,8 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
} }
} }
else { else {
/* /* We got a byte of data */
* We got a whole chunk of data, which can be anything from one nread++;
* byte to a set of lines and possibly just a piece of the last
* line.
*/
int i;
nread += gotbytes;
if(keepon > TRUE) { if(keepon > TRUE) {
/* This means we are currently ignoring a response-body */ /* This means we are currently ignoring a response-body */
@ -368,7 +362,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
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! */
cl -= gotbytes; cl--;
if(cl<=0) { if(cl<=0) {
keepon = FALSE; keepon = FALSE;
break; break;
@ -382,7 +376,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
/* now parse the chunked piece of data so that we can /* now parse the chunked piece of data so that we can
properly tell when the stream ends */ properly tell when the stream ends */
r = Curl_httpchunk_read(conn, ptr, gotbytes, &tookcareof); r = Curl_httpchunk_read(conn, ptr, 1, &tookcareof);
if(r == CHUNKE_STOP) { if(r == CHUNKE_STOP) {
/* we're done reading chunks! */ /* we're done reading chunks! */
infof(data, "chunk reading DONE\n"); infof(data, "chunk reading DONE\n");
@ -395,16 +389,13 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
tookcareof); tookcareof);
} }
} }
else else {
for(i = 0; i < gotbytes; ptr++, i++) {
perline++; /* amount of bytes in this line so far */ perline++; /* amount of bytes in this line so far */
if(*ptr == 0x0a) { if(*ptr == 0x0a) {
char letter;
int writetype; int writetype;
/* convert from the network encoding */ /* convert from the network encoding */
result = Curl_convert_from_network(data, line_start, result = Curl_convert_from_network(data, line_start, perline);
perline);
/* Curl_convert_from_network calls failf if unsuccessful */ /* Curl_convert_from_network calls failf if unsuccessful */
if(result) if(result)
return result; return result;
@ -455,13 +446,11 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
attention so that this is cleared again when this attention so that this is cleared again when this
function returns! */ function returns! */
k->ignorebody = TRUE; k->ignorebody = TRUE;
infof(data, "%zd bytes of chunk left\n", gotbytes-i);
if(line_start[1] == '\n') { if(line_start[1] == '\n') {
/* this can only be a LF if the letter at index 0 /* this can only be a LF if the letter at index 0
was a CR */ was a CR */
line_start++; line_start++;
i++;
} }
/* now parse the chunked piece of data so that we can /* now parse the chunked piece of data so that we can
@ -487,22 +476,13 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
keepon=FALSE; keepon=FALSE;
} }
} }
else { else
keepon = FALSE; keepon = FALSE;
if(200 == data->info.httpproxycode) {
if(gotbytes - (i+1))
failf(data, "Proxy CONNECT followed by %zd bytes "
"of opaque data. Data ignored (known bug #39)",
gotbytes - (i+1));
}
}
/* we did the full CONNECT treatment, go to COMPLETE */ /* we did the full CONNECT treatment, go to COMPLETE */
conn->tunnel_state[sockindex] = TUNNEL_COMPLETE; conn->tunnel_state[sockindex] = TUNNEL_COMPLETE;
break; /* breaks out of for-loop, not switch() */ break; /* breaks out of for-loop, not switch() */
} }
/* keep a backup of the position we are about to blank */
letter = line_start[perline];
line_start[perline]=0; /* zero terminate the buffer */ line_start[perline]=0; /* zero terminate the buffer */
if((checkprefix("WWW-Authenticate:", line_start) && if((checkprefix("WWW-Authenticate:", line_start) &&
(401 == k->httpcode)) || (401 == k->httpcode)) ||
@ -562,12 +542,13 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
/* store the HTTP code from the proxy */ /* store the HTTP code from the proxy */
data->info.httpproxycode = k->httpcode; data->info.httpproxycode = k->httpcode;
} }
/* put back the letter we blanked out before */
line_start[perline]= letter;
perline=0; /* line starts over here */ perline=0; /* line starts over here */
line_start = ptr+1; /* this skips the zero byte we wrote */ ptr = data->state.buffer;
line_start = ptr;
} }
else /* not end of header line */
ptr++;
} }
} }
break; break;