mirror of
https://github.com/d0zingcat/cors-anywhere.git
synced 2026-05-13 15:09:25 +00:00
Show "400 Missing slash" when needed #238
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user