Permalink
Browse files

Do not send Access-Control-Max-Age header if corsMaxAge is 0 (default)

  • Loading branch information...
gnjack committed Jul 14, 2017
1 parent 10df7c9 commit 49d429dd60f9e6186d2269968e601f154ffdb932
Showing with 3 additions and 8 deletions.
  1. +1 −2 README.md
  2. +1 −1 lib/cors-anywhere.js
  3. +1 −5 test/test.js
@@ -107,8 +107,7 @@ proxy requests. The following options are supported:
Example: `["cookie"]`
* dictionary of lowercase strings `setHeaders` - Set headers for the request (overwrites existing ones).
Example: `{"x-powered-by": "CORS Anywhere"}`
* number `corsMaxAge` - If set, an Access-Control-Max-Age request header with this value (in seconds) will be added.
Defaults to 0.
* number `corsMaxAge` - If set, an Access-Control-Max-Age request header with this value (in seconds) will be added.
Example: `600` - Allow CORS preflight request to be cached by the browser for 10 minutes.
* string `helpFile` - Set the help file (shown at the homepage).
Example: `"myCustomHelpText.txt"`
@@ -53,7 +53,7 @@ function isValidHostName(hostname) {
function withCORS(headers, request) {
headers['access-control-allow-origin'] = '*';
var corsMaxAge = request.corsAnywhereRequestState.corsMaxAge;
if (corsMaxAge != null) {
if (corsMaxAge) {
headers['access-control-max-age'] = corsMaxAge;
}
if (request.headers['access-control-request-method']) {
@@ -50,7 +50,6 @@ describe('Basic functionality', function() {
.get('/')
.type('text/plain')
.expect('Access-Control-Allow-Origin', '*')
.expect('Access-Control-Max-Age', '0')
.expect(200, helpText, done);
});
@@ -92,7 +91,6 @@ describe('Basic functionality', function() {
request(cors_anywhere)
.get('/example.com')
.expect('Access-Control-Allow-Origin', '*')
.expect('Access-Control-Max-Age', '0')
.expect('x-request-url', 'http://example.com/')
.expect(200, 'Response from example.com', done);
});
@@ -841,9 +839,7 @@ describe('Access-Control-Max-Age set', function() {
describe('Access-Control-Max-Age not set', function() {
before(function() {
cors_anywhere = createServer({
corsMaxAge: null,
});
cors_anywhere = createServer();
cors_anywhere_port = cors_anywhere.listen(0).address().port;
});
after(stopServer);

0 comments on commit 49d429d

Please sign in to comment.