mirror of
https://github.com/d0zingcat/cors-anywhere.git
synced 2026-05-13 15:09:25 +00:00
Better description for non-proxied requests
This commit is contained in:
@@ -135,16 +135,17 @@ var getHandler = exports.getHandler = function(options) {
|
||||
// 1:protocol 3:hostname 4:port 5:path + query string
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// 2:host
|
||||
if (!match || (match[2].indexOf('.') === -1 && match[2].indexOf(':') === -1) || match[4] > 65535) {
|
||||
// Incorrect usage. Show how to do it correctly.
|
||||
showUsage(cors_headers, res);
|
||||
return;
|
||||
} else if (match[2] === 'iscorsneeded') {
|
||||
// Is CORS needed? This path is provided so that API consumers can test whether it's necessary
|
||||
// to use CORS. The server's reply is always No, because if they can read it, then CORS headers
|
||||
// are not necessary.
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('no');
|
||||
if (!match || (match[2].indexOf('.') === -1 && match[2].indexOf(':') === -1)) {
|
||||
if (match && match[2] === 'iscorsneeded') {
|
||||
// Is CORS needed? This path is provided so that API consumers can test whether it's necessary
|
||||
// to use CORS. The server's reply is always No, because if they can read it, then CORS headers
|
||||
// are not necessary.
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('no');
|
||||
} else {
|
||||
// Incorrect usage. Show how to do it correctly.
|
||||
showUsage(cors_headers, res);
|
||||
}
|
||||
return;
|
||||
} else if (match[4] > 65535) {
|
||||
// Port is higher than 65535
|
||||
@@ -153,11 +154,11 @@ var getHandler = exports.getHandler = function(options) {
|
||||
return;
|
||||
} else if ( hasNoContent(match[3]) ) {
|
||||
// Don't even try to proxy invalid hosts
|
||||
res.writeHead(404, cors_headers);
|
||||
res.writeHead(404, 'Invalid host', cors_headers);
|
||||
res.end();
|
||||
return;
|
||||
} else if (corsAnywhere.requireHeader != null && req.headers[corsAnywhere.requireHeader.toLowerCase()] == null) {
|
||||
res.writeHead(400, cors_headers);
|
||||
res.writeHead(400, 'Header required', cors_headers);
|
||||
res.end('Missing ' + corsAnywhere.requireHeader + ' header!');
|
||||
return;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user