Better description for non-proxied requests

This commit is contained in:
Rob W
2013-01-04 23:53:00 +01:00
parent 098f425d0a
commit eb5c57e729

View File

@@ -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 {