Commit Graph

119 Commits

Author SHA1 Message Date
Rob Wu
20d5d0480e test-memory: destroy response to free socket
Starting from Node 12, the test started to fail because of
intermittent socket errors, such as ECONNRESET and "socket hang up".

Destroying the response before triggering a new request resolves it.
2020-05-02 17:20:16 +02:00
Rob Wu
7222fce684 Extend supported Node.js from <=9 to <=14 2020-05-02 16:45:42 +02:00
Rob Wu
4814647a9d Reject invalid requests instead of crashing (#142) 2018-10-31 23:58:21 +01:00
Rob Wu
462f844e22 Fix failing test in test/test-ratelimit 2018-10-31 12:28:55 +01:00
Rob Wu
2ee31471ce Version 0.4.1
- Add ability to rate-limit/block requests by origin (#45).
- Avoid crashing on invalid HTTP status codes (#95).
- Support and test coverage for latest Node.js versions (up to 9).
- Support `Access-Control-Max-Age` via `corsMaxAge` option.
- Listen on `0.0.0.0:8080` by default instead of `127.0.0.1:8080`.
  (use `HOST` and `PORT` environment variables to override this).
- Update gTLD list.
2017-12-01 14:05:34 +01:00
Rob Wu
b419acc6e5 Explicitly list all files for the npm package 2017-12-01 14:05:25 +01:00
Rob Wu
7b6ce1a3df Fix failing tests for 0.10.x, 4.x and 5.x
Travis build failed on "Uncaught TypeError: Object.keys called on non-object".
That's a real error (res._headers was initially null until a header is set).
2017-11-11 02:08:44 +01:00
Rob Wu
d2b5dd38bb Add Node 9.x to Travis
Locally tested that the tests pass with Node 9.0.0 and 9.1.0
Also modified a test expectation for Node 9.0.0+
2017-11-11 01:32:39 +01:00
Rob Wu
6741f810f9 Remove engines.npm (#92)
NPM 5.5.1 is not compatible with Node.js 9.1.0.
Let's use the npm that ships with node.
2017-11-11 01:32:29 +01:00
Rob Wu
53101b9a21 Update gTLD list 2017-11-11 00:34:56 +01:00
Rob Wu
4a46541da4 Catch error due to invalid status code (#95) 2017-11-08 22:23:58 +01:00
Rob Wu
143eff177c Merge pull request #77 from gnjack/maxAge
Allow caching of CORS headers by setting Access-Control-Max-Age header
2017-07-16 11:10:36 +02:00
Jack Tench
49d429dd60 Do not send Access-Control-Max-Age header if corsMaxAge is 0 (default) 2017-07-14 13:22:53 +01:00
Jack Tench
10df7c9f4a Rename maxAge to corsMaxAge and set the default corsMaxAge to 0.
Set corsAnywhereRequestState before calling withCORS and use the state instead of a parameter to get corsMaxAge.
2017-07-14 12:29:15 +01:00
Jack Tench
881392cfaf Add maxAge config option. If set, an Access-Control-Max-Age header with this value (in seconds) will be added. 2017-07-13 19:13:37 +01:00
Rob Wu
70400ab166 Monkey-patch nock, add Node v8 to test matrix 2017-07-13 18:58:29 +02:00
Rob Wu
f016bd71f5 Update test expectation for "100 GET requests 50k"
Locally Node v7 and v8 also have higher memory expectations,
so just use the same maximum memory value for v0.x and non-v0.x.
2017-07-13 18:57:26 +02:00
Rob Wu
99133b02b4 Explicit Node versions in Travis build matrix
This communicates more clearly for which versions of Node.js
the tests have run.

8 is not listed because tests are failing due to the nock HTTP mocking
library being incompatible with Node v8.
2017-07-13 18:09:52 +02:00
Rob Wu
ded44cb5d0 Upgrade supertest + nock to recent version
The most recent version that was explicitly marked as compatible with
Node.js 0.10.x
2017-07-13 17:32:45 +02:00
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
81ed058784 Update mocha to ^3.4.2
to unlock goodies such as --inspect / --inspect-brk
2017-07-13 12:45:44 +02:00
Alexander Pinnecke
97c6e53020 Fixed example in README to bind correct host 2017-02-03 15:03:05 +01:00
Rob Wu
efc13eec1f Correctly parse environment list in server.js
Previously an unset value resulted in [""] instead of [].
2016-05-31 20:33:05 +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
f07bdc4ea0 Add examples for modifying requests or responses 2016-05-14 23:16:45 +02:00
Rob Wu
bb4293a74d Version 0.4.0
- CI & 100% test coverage
- Do not crash when a malformed HTTP response is received.
- Remove getHandler (its documented form was broken anyway).
- Allow custom help file to be set.
- Add option to redirect same-origin requests instead of proxying them.
2016-03-19 19:17:18 +01: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
Rob Wu
66fdd6e662 100% test coverage :) 2016-02-26 18:23:29 +01:00
Rob Wu
411e95ac1d Merge pull request #40 from Rise-Vision/feature/custom-help-text
Feature/custom help text
2016-02-26 18:19:30 +01:00
rodrigopavezi
9f389e6f41 Added option for a custom help file 2016-02-26 14:16:20 -03:00
Rob Wu
ee93f70dc3 Increment threshold for memory failure on Node 0.x 2016-02-26 17:05:06 +01:00
Rob Wu
f081fe2ccf Fix tests: Explicitly start and close servers
Otherwise these tests fail on Node 0.10.x
2016-02-26 16:58:07 +01:00
Rob Wu
37f35fda35 Exclude coverage/ from linting 2016-02-26 16:32:47 +01: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
1308e34247 More test coverage for redirects 2016-02-26 16:10:53 +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
f9af03e762 Add Travis and test coverage
Notes:
- npm run test also runs the memory tests, which might be flaky on
  some systems.
- npm run test-coverage only runs the unit tests (it can't run the
  memory test anyway because the memory tests create a Node child
  process, and istanbul cannot cover that).
2016-02-26 12:38:59 +01:00
Rob Wu
0872577729 Enforce a consistent coding style using eslint 2016-02-26 12:31:35 +01:00
Rob Wu
e8f0e64168 Version 0.3.0
- Support proxying through proxy (`getProxyForUrl` option, defaulting to
  proxy configuration from the environment variables, see
  https://github.com/Rob--W/proxy-from-env) (#37).
- Update gTLD list.
2016-02-19 00:48:45 +01:00
Rob Wu
97b09d599d Update gTLD list 2016-02-19 00:47:39 +01:00
Rob Wu
bbe3378c35 Tests: Replace space with dash in header name
Node.js has forbidden header names with spaces in
6192c9892f.

The next error is thrown when the test sets the "some header" header:
Uncaught TypeError: Header name must be a valid HTTP Token ["some header"]

To fix it, replace spaces with dashes.
2016-02-19 00:39:17 +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
440d2de180 Version 0.2.5
- Add setHeaders to replace request headers with a fixed value (#33).
2015-08-23 14:48:29 +02:00
Rob Wu
a2f0c05b24 Add more tests for setHeaders 2015-08-23 10:58:58 +02: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
8429bb3c58 Version 0.2.4
- Add originBlacklist (#32) and originWhitelist (#24) options.
- Update gTLD list.
2015-08-16 01:12:12 +02:00