Commit Graph

103 Commits

Author SHA1 Message Date
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
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
7a138b36cc Version 0.2.3
Changes:
- Updated to node-http-proxy 1.11.1 from 1.3.0
- Add httpsOptions configuration to listen as a https server.
- Update gTLD list, and allow requests to unlisted TLDs if the
  scheme is explicitly set (#14).
- Added loads of unit tests and automatic memory leak tests.
2015-05-09 11:26:23 +02:00
Rob Wu
f8f718ead8 Add tests for memory leaks
Using the performNRequests, I collected the following statistics
before choosing the maximum allowed "leaked" memory.

Node.js 0.12.2,
Using the http module ('use-http-instead-of-cors-anywhere'):

Memory usage delta: 132800 (100 requests of 50 kb each, 250ms)
Memory usage delta: 110144 (100 requests of 1 kb each, 172ms)
Memory usage delta: 709936 (1000 requests of 1 kb each, 902ms)
Memory usage delta: 865104 (10000 requests of 1 kb each, 7073ms)
Memory usage delta: 930416 (100000 requests of 1 kb each, 62856ms)

Using CORS Anywhere:

Memory usage delta: 356784 (100 requests of 50 kb each, 1004ms)
Memory usage delta: 355248 (100 requests of 1 kb each, 641ms)
Memory usage delta: 1326856 (1000 requests of 1 kb each, 3338ms)
Memory usage delta: 1462584 (10000 requests of 1 kb each, 21186ms)
Memory usage delta: 1473624 (100000 requests of 1 kb each, 211202ms)

Clearly, there is a small leak, but it is not proportional/linear
in terms of the number of requests, so the observed "leak" is probably
not an issue. Furthermore, the "leak" also occurs with the plain
http module.

After setting fixed limits, I ran the tests on Node.js 0.10.25 and
observed that the tests failed due to the too low limits, so I
incremented the limits (400 -> 550, 1500 -> 2000).
2015-05-09 11:23:27 +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
d437bc9225 Test that redirect headers are not set in response 2015-05-06 20:02:55 +02:00
Rob Wu
b5d601f823 Verify and update links to node-http-proxy 2015-05-06 19:53:57 +02:00
Rob Wu
024d540e7c Fix test expectations for xfwd 2015-05-06 19:46:58 +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
f98705f27b Add test for proxy error 2015-05-06 18:40:04 +02:00
Rob Wu
e8202aa31f Add more xfwd tests (https+http & http+https) 2015-05-06 18:20:11 +02:00
Rob Wu
056cb446fe x-forwarded-port should match the request port.
Not the proxied one. These tests will now fail, but that's because
the current implementation is apparently incorrect.
2015-05-06 12:08:53 +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