Commit Graph

57 Commits

Author SHA1 Message Date
Rob Wu
dcc64052e3 Change response handling hook
When proxyReq is aborted (by us - in response to a redirect response),
it can ultimately trigger an "error" event of type ECONNRESET.
This error was unconditionally propagated to the error handler:
https://github.com/nodejitsu/node-http-proxy/blob/v1.11.1/lib/http-proxy/passes/web-incoming.js#L134-L140

Our proxy error handler responds by writing a response + error code,
which prevents the response from being overwritten.

I found this after upgrading the nock library to 5.2.1+, which contains
510e31c73e
The redirect tests that were previously passing in Node 0.10.x were
failing, with errors like "Can't set headers after they are sent.".

The new implementation makes sure that the proxied response is not
forwarded to the original response.
2017-07-13 17:08:31 +02:00
Rob Wu
6c4234f2b3 Add rate-limiting functionality #45
- Add checkRateLimit option to the API.
- Extend the default server.js with environment variables
  CORSANYWHERE_WHITELIST (re-using originWhitelist) and
  CORSANYWHERE_RATELIMIT (using the new checkRateLimit option)
  to make it easy to enforce usage limits.
- Document that Heroku doesn't want open proxies.
2016-05-31 00:52:26 +02:00
Rob Wu
e6695b8102 Add redirectSameOrigin
Some clients try to use CORS Anywhere, even for same-origin requests...
Add a new setting "redirectSameOrigin" to not waste server resources on
proxying such requests.

Fixes #42
2016-03-19 18:35:17 +01:00
Rob Wu
bacbbe0cb0 It's 2016
(and remove unnecessary section about Dependencies,
because it mentioned 3x in the previous section and package.json)
2016-02-26 18:26:40 +01:00
rodrigopavezi
9f389e6f41 Added option for a custom help file 2016-02-26 14:16:20 -03:00
Rob Wu
fc9cf157d2 Remove getHandler
It is not supported, and its current form was not documented.
If you need to proxy a request without listening on a port, just
dispatch a 'request' event on the return value of createServer().
2016-02-26 16:21:59 +01:00
Rob Wu
35932a0ac1 Add tests for misbehaving servers + fix bug 2016-02-26 15:51:17 +01:00
Rob Wu
16b1a7e3a0 requireHeader: Improve coverage and fix bug
When the single-string version of requireHeader was used, it was not
properly transformed to a lowercase string. Now it is.
2016-02-26 13:13:58 +01:00
Rob Wu
24db52500f Remove requiresPort dependency
location.host is directly parsed from the full URL, so the
"concatenate host and port" branch was never taken.
2016-02-26 12:58:11 +01:00
Rob Wu
0872577729 Enforce a consistent coding style using eslint 2016-02-26 12:31:35 +01:00
Rob Wu
97b09d599d Update gTLD list 2016-02-19 00:47:39 +01:00
Rob Wu
8568c06b17 Support proxying through a proxy - #37
Automatically respects proxy headers from environment variables,
using https://github.com/Rob--W/proxy-from-env
2016-02-19 00:22:20 +01:00
Rob Wu
015627b3f4 setHeaders is a dict, not an array 2015-08-23 10:52:01 +02:00
Nikolay Derkach
c5a3877e6c add setHeaders option 2015-08-22 16:49:59 -07:00
Rob Wu
c0048573e9 Update gTLD list 2015-08-16 01:11:11 +02:00
Rob Wu
837dee582c Add originBlacklist + originWhitelist
- originWhitelist resolves #24
- originBlacklist may help with #32
2015-08-16 01:05:26 +02:00
Rob Wu
0e594a2b03 Skip host check if scheme is explicitly set
Fixes https://github.com/Rob--W/cors-anywhere/issues/14

This allows CORS anywhere to be forwards-compatible with the surge
of new gTLDs.
2015-05-09 11:09:59 +02:00
Rob Wu
903f3d32dc Update TLD list. 2015-05-06 20:15:50 +02:00
Rob Wu
fbf3ce9255 Update copyright year to 2015 2015-05-06 20:15:50 +02:00
Rob Wu
19de080098 Move inline jshint directive to .jshintrc 2015-05-06 20:15:50 +02:00
Rob Wu
b5d601f823 Verify and update links to node-http-proxy 2015-05-06 19:53:57 +02:00
Rob Wu
2d84862546 Upgrade http-proxy to 1.11.1
All xfwd and tests fails with this change, but that's because the
tests themselves were incorrect (using port 80/443 instead of the
ephemeral ports created for the tests).
2015-05-06 19:19:21 +02:00
Rob Wu
80da247827 Add httpsOptions option to create https.Server
Note: This does not work with the current version of node-http-proxy
and node 0.12.0 because req.connection.pair is not defined.
2015-05-06 12:07:31 +02:00
Rob Wu
6b54191df9 0.2.2 - Expose every response header #12 2014-10-05 16:14:49 +02:00
Rob Wu
0745b894c6 0.2.1 - Update URL parsing logic (fixes #9) 2014-08-29 16:30:50 +02:00
Rob Wu
90d81e7033 Update TLD list 2014-08-25 13:43:13 +02:00
Rob Wu
bd9af5849f Upgrade from http-proxy 0.10.x to 1.3.0 2014-08-25 13:39:25 +02:00
Rob Wu
beadd3fe77 v0.1.9 - Always use Access-Control-Allow-Origin: *
Fixes #6
2014-03-12 18:18:08 +01:00
Rob Wu
a322df91c4 Header checks after error checks
With this commit, you will see the following messages instead of
"Missing required request header ...":

 /iscorsneeded = no with direct browsing
 /favicon.ico = 404 not found
2013-09-10 23:10:14 +02:00
Rob Wu
d2023b45e1 Fix POST -> GET conversion on redirect 2013-08-30 11:42:51 +02:00
Rob Wu
a784fc96f8 Simplified demo.html; show proxyError on error 2013-08-29 19:20:40 +02:00
Rob Wu
cd97423db9 Fix memory leak 2013-08-29 15:17:19 +02:00
Rob Wu
a56fb8843c Add X-Final-URL 2013-08-29 10:12:03 +02:00
Rob Wu
721ba7609d Remove unused code 2013-08-28 21:04:48 +02:00
Rob Wu
3bb98d6bea Add X-CORS-Redirect-# header for debugging 2013-08-28 20:50:46 +02:00
Rob Wu
d7a6564574 Bind proxyRequest event handler once per proxy
Optimization: Create onProxyResponse handler only once,
and bind it only once per HttpProxy instance
(opposed to binding it for every request)
2013-08-28 19:48:52 +02:00
Rob Wu
96d237e7b3 [WIP] Support internal redirects
TODO:
- Move proxyRequest elsewhere, and attach the request state to req
- Investigate the implications of calling req.emit('end');
  (It's called in order to trigger reverseProxy.end(), needed to start
  the redirect)
2013-08-28 18:49:51 +02:00
Rob Wu
de0318bc4c Refactored; move URL parser to separate function 2013-08-28 17:35:23 +02:00
Rob Wu
c37e496dee Add extra documentation (in code).
Removed ? from path's regexp, because
"http://cors-anywhere/" + "/domain.com/file" =
"http://cors-anywhere//domain.com/file" SHOULD be an invalid request.

"//domain.com/file" can be resolved to "http://domain.com/file", but
"/domain.com/file" should resolved to http://host/domain.com/file,
but since the host is unknown, the API should just fail.
2013-08-28 13:17:58 +02:00
Rob Wu
198e927baa Use proxyRequest event instead of subst. writeHead
Makes the code less dependent on implementation details.
2013-08-28 11:49:39 +02:00
Rob Wu
9410ff5afa Remove manual redirect handling
From now on, redirects will automatically be handled by the browser.
Using the API by clients has become extremely easy.

Included JavaScript / jQuery snippets in the documentation to
demonstrate that it's easy to use the API.
2013-08-27 18:51:04 +02:00
Rob Wu
61d55ae41e Avoid preflight request by relaxing header req
One of the following headers is required by default:
- Origin: This header is always sent with CORS requests.
- X-Requested-With: This header is automatically added by jQuery on
  same-origin requests.

These two headers effectively disable the ability to use the CORS
proxy for regular browsing.
2013-08-27 16:15:10 +02:00
Rob Wu
6d9b268ecc Update header-modifying method - v0.1.4
node-http-proxy sets headers before using writeHead.
2013-07-23 22:29:02 +02:00
Rob Wu
b35a6f5ffb Redirect URL in statusText
Android's stock browser (and Webview) does not recognize the
Access-Control-Expose-headers response header.
Use the status text field to pass through this information.

Updated demo and documentation.
2013-07-23 21:55:32 +02:00
Rob Wu
aee875ac67 https -> target.https 2013-06-10 18:38:15 +02:00
Rob Wu
367b648114 Avoid double ports in host header
Previously, it was possible that the host header looks
like domain.com:4444:4444 - obviously a bug.
2013-06-10 18:15:25 +02:00
kybernetikos
808e1761ef Make the proxy request use the correct protocol (http/https).
I discovered that the proxy request was using http even when it
was proxying to an https port / url.  This is because we didn't pass
the https parameter through in the proxyRequest method.
2013-06-10 16:41:13 +01:00
Rob Wu
59d5bc6043 Set Host header based on actual input
Fixes #1
2013-03-30 17:40:54 +01:00
Rob W
407ba84a10 Avoid duplicate Access-Control-Expose-Headers 2013-01-05 11:05:32 +01:00
Rob W
eb5c57e729 Better description for non-proxied requests 2013-01-04 23:59:52 +01:00