mirror of
https://github.com/d0zingcat/cors-anywhere.git
synced 2026-05-31 07:26:54 +00:00
add setHeaders option
This commit is contained in:
@@ -100,6 +100,8 @@ The following options are recognized by both methods:
|
||||
Example: `['Origin', 'X-Requested-With']`.
|
||||
* array of lowercase strings `removeHeaders` - Exclude certain headers from being included in the request.
|
||||
Example: `["cookie"]`
|
||||
* dictionary of lowercase strings `setHeaders` - Set headers for the request (overwrites existing ones).
|
||||
Example: `{"x-powered-by": "CORS Anywhere"}`
|
||||
|
||||
`createServer` recognizes the following option as well:
|
||||
|
||||
|
||||
@@ -200,7 +200,8 @@ var getHandler = exports.getHandler = function(options, proxy) {
|
||||
originBlacklist: [], // Requests from these origins will be blocked.
|
||||
originWhitelist: [], // If non-empty, requests not from an origin in this list will be blocked.
|
||||
requireHeader: null, // Require a header to be set?
|
||||
removeHeaders: [] // Strip these request headers
|
||||
removeHeaders: [], // Strip these request headers.
|
||||
setHeaders: [] // Set these request headers.
|
||||
};
|
||||
if (options) {
|
||||
Object.keys(corsAnywhere).forEach(function(option) {
|
||||
@@ -293,6 +294,9 @@ var getHandler = exports.getHandler = function(options, proxy) {
|
||||
delete req.headers[header];
|
||||
});
|
||||
|
||||
Object.keys(corsAnywhere.setHeaders).forEach(function(header) {
|
||||
req.headers[header] = corsAnywhere.setHeaders[header];
|
||||
});
|
||||
|
||||
req.corsAnywhereRequestState = {
|
||||
location: location,
|
||||
|
||||
20
test/test.js
20
test/test.js
@@ -478,6 +478,26 @@ describe('removeHeaders', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('setHeaders', function() {
|
||||
before(function() {
|
||||
cors_anywhere = createServer({
|
||||
setHeaders: {'x-powered-by': 'CORS Anywhere'},
|
||||
});
|
||||
cors_anywhere_port = cors_anywhere.listen(0).address().port;
|
||||
});
|
||||
after(stopServer);
|
||||
|
||||
it('GET /example.com', function(done) {
|
||||
request(cors_anywhere)
|
||||
.get('/example.com/echoheaders')
|
||||
.expect('Access-Control-Allow-Origin', '*')
|
||||
.expectJSON({
|
||||
host: 'example.com',
|
||||
'x-powered-by': 'CORS Anywhere'
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('httpProxyOptions.xfwd=false', function() {
|
||||
before(function() {
|
||||
cors_anywhere = createServer({
|
||||
|
||||
Reference in New Issue
Block a user