HTTP proxy: insert slash in URL if missing

curl has been accepting URLs using slightly wrong syntax for a long
time, such as when completely missing as slash "http://example.org" or
missing a slash when a query part is given
"http://example.org?q=foobar".

curl would translate these into a legitimate HTTP request to servers,
although as was shown in bug #1206 it was not adjusted properly in the
cases where a HTTP proxy was used.

Test 1213 and 1214 were added to the test suite to verify this fix.

The test HTTP server was adjusted to allow us to specify test number in
the host name only without using any slashes in a given URL.

Bug: http://curl.haxx.se/bug/view.cgi?id=1206
Reported by: ScottJi
This commit is contained in:
Daniel Stenberg 2013-03-15 14:18:16 +01:00
parent b50285d751
commit e4b733e3f1
6 changed files with 197 additions and 9 deletions

View file

@ -507,15 +507,24 @@ static int ProcessRequest(struct httprequest *req)
else
req->partno = 0;
sprintf(logbuf, "Requested test number %ld part %ld",
req->testno, req->partno);
logmsg("%s", logbuf);
if(req->testno) {
/* find and parse <servercmd> for this test */
parse_servercmd(req);
sprintf(logbuf, "Requested test number %ld part %ld",
req->testno, req->partno);
logmsg("%s", logbuf);
/* find and parse <servercmd> for this test */
parse_servercmd(req);
}
else
req->testno = DOCNUMBER_NOTHING;
}
else {
if(req->testno == DOCNUMBER_NOTHING) {
/* didn't find any in the first scan, try alternative test case
number placements */
if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
doc, &prot_major, &prot_minor) == 3) {
char *portp = NULL;
@ -563,8 +572,39 @@ static int ProcessRequest(struct httprequest *req)
parse_servercmd(req);
}
else {
logmsg("Did not find test number in PATH");
req->testno = DOCNUMBER_404;
/* there was no trailing slash and it wasn't CONNECT, then we get the
the number off the last dot instead, IE we consider the TLD to be
the test number. Test 123 can then be written as
"example.com.123". */
/* find the last dot */
ptr = strrchr(doc, '.');
/* get the number after it */
if(ptr) {
ptr++; /* skip the dot */
req->testno = strtol(ptr, &ptr, 10);
if(req->testno > 10000) {
req->partno = req->testno % 10000;
req->testno /= 10000;
}
else
req->partno = 0;
sprintf(logbuf, "Requested test number %ld part %ld (from host name)",
req->testno, req->partno);
logmsg("%s", logbuf);
}
if(!req->testno) {
logmsg("Did not find test number in PATH");
req->testno = DOCNUMBER_404;
}
else
parse_servercmd(req);
}
}
}