diff --git a/lib/cors-anywhere.js b/lib/cors-anywhere.js index 4aa994c..e2a93b2 100644 --- a/lib/cors-anywhere.js +++ b/lib/cors-anywhere.js @@ -258,7 +258,7 @@ var getHandler = exports.getHandler = function(options, proxy) { return; } - if (!isValidHostName(location.hostname)) { + if (!/^\/https?:/.test(req.url) && !isValidHostName(location.hostname)) { // Don't even try to proxy invalid hosts (such as /favicon.ico, /robots.txt) res.writeHead(404, 'Invalid host', cors_headers); res.end('Invalid host: ' + location.hostname); diff --git a/test/setup.js b/test/setup.js index 5c538dc..fb87d9b 100644 --- a/test/setup.js +++ b/test/setup.js @@ -97,3 +97,7 @@ echoheaders('http://example.com'); echoheaders('http://example.com:1337'); echoheaders('https://example.com'); echoheaders('https://example.com:1337'); + +nock('http://robots.txt') + .get('/') + .reply(200, 'this is http://robots.txt'); diff --git a/test/test.js b/test/test.js index 9a236e2..5c1714d 100644 --- a/test/test.js +++ b/test/test.js @@ -78,6 +78,13 @@ describe('Basic functionality', function() { .expect(404, 'Invalid host: robots.txt', done); }); + it('GET /http://robots.txt should be proxied', function(done) { + request(cors_anywhere) + .get('/http://robots.txt') + .expect('Access-Control-Allow-Origin', '*') + .expect(200, 'this is http://robots.txt', done); + }); + it('GET /example.com', function(done) { request(cors_anywhere) .get('/example.com')