Show "400 Missing slash" when needed #238

This commit is contained in:
Rob Wu
2021-03-22 21:18:31 +01:00
parent 207e1e9ed9
commit 34ec83b25c
2 changed files with 9 additions and 1 deletions

View File

@@ -316,6 +316,14 @@ function getHandler(options, proxy) {
}
if (!location) {
// Special case http:/notenoughslashes, because new users of the library frequently make the
// mistake of putting this application behind a server/router that normalizes the URL.
// See https://github.com/Rob--W/cors-anywhere/issues/238#issuecomment-629638853
if (/^\/https?:\/[^/]/i.test(req.url)) {
res.writeHead(400, 'Missing slash', cors_headers);
res.end('The URL is invalid: two slashes are needed after the http(s):.');
return;
}
// Invalid API call. Show how to correctly use the API
showUsage(corsAnywhere.helpFile, cors_headers, res);
return;

View File

@@ -141,7 +141,7 @@ describe('Basic functionality', function() {
request(cors_anywhere)
.get('/http:/notenoughslashes')
.expect('Access-Control-Allow-Origin', '*')
.expect(200, helpText, done);
.expect(400, 'The URL is invalid: two slashes are needed after the http(s):.', done);
});