From eb5c57e729ea4321b70557f0eca22b0fd5b83e47 Mon Sep 17 00:00:00 2001 From: Rob W Date: Fri, 4 Jan 2013 23:53:00 +0100 Subject: [PATCH] Better description for non-proxied requests --- lib/cors-anywhere.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/cors-anywhere.js b/lib/cors-anywhere.js index bff0e97..e20ed46 100644 --- a/lib/cors-anywhere.js +++ b/lib/cors-anywhere.js @@ -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 {