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

This commit is contained in:
Jack Tench
2017-07-14 13:22:53 +01:00
parent 10df7c9f4a
commit 49d429dd60
3 changed files with 3 additions and 8 deletions

View File

@@ -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"`

View File

@@ -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']) {

View File

@@ -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);