Skip to content

Commit

Permalink
Show "400 Missing slash" when needed Rob--W#238
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W committed Mar 22, 2021
1 parent 207e1e9 commit 34ec83b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/cors-anywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


Expand Down

0 comments on commit 34ec83b

Please sign in to comment.