Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

set Accept header to */* if raw param is set #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ app.get('/', function(req, res) {
// do proxy

// copy headers from the external request, but remove those that node should generate
var externalReqHeaders = u.omit(req.headers, 'accept-encoding', 'connection', 'cookie', 'host', 'user-agent');
externalReqHeaders.accept = 'application/json';
var externalReqHeaders = u.omit(req.headers, 'accept-encoding', 'connection', 'cookie', 'host', 'user-agent'),
raw = params.raw; // undocumented, for now
externalReqHeaders.accept = raw ? '*/*' : 'application/json';

request({
uri: apiUrl,
Expand All @@ -56,7 +57,6 @@ app.get('/', function(req, res) {
encoding: 'utf8'
}, function(error, response, body){
var callbackName = params.callback || params.jsonp,
raw = params.raw, // undocumented, for now
status;

if (error){
Expand Down
16 changes: 16 additions & 0 deletions test/server_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,20 @@ describe('app', function(){

});
});

it('should set the Accept header to "*/*" for "raw" requests', function(done){
var destApp = express();
destApp.get('/', function(req, res){
expect(req.headers.accept).to.eql('*/*');
res.send('');
});
var server = http.createServer(destApp);
server.listen(8001, function(){

supertest(app)
.get('/')
.query({url: 'http://localhost:8001', raw: true})
.expect(200, done);
});
});
});