diff options
author | Daniel Stenberg <daniel@haxx.se> | 2013-03-15 14:18:16 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2013-03-15 14:18:16 +0100 |
commit | e4b733e3f1a771bd1017cdcfb355fcb9caffe646 (patch) | |
tree | 862fa85997d33e26f9e30b7949cbddfb6ad8f91a /tests/server | |
parent | b50285d751855440252904c76995b6de193c2dc2 (diff) |
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
Diffstat (limited to 'tests/server')
-rw-r--r-- | tests/server/sws.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/tests/server/sws.c b/tests/server/sws.c index a7de09f92..aef55ea96 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -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) { + + 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); + /* 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); } } } |