Skip to content

Commit

Permalink
Merge pull request #742 from jugglinmike/option-content-length
Browse files Browse the repository at this point in the history
Set `Content-Length` header for OPTIONS requests
  • Loading branch information
jcrugzz committed Nov 25, 2014
2 parents aba505d + 8a24a1e commit 3194d81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/http-proxy/passes/web-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ web_o = Object.keys(web_o).map(function(pass) {
*/

function deleteLength(req, res, options) {
if(req.method === 'DELETE' && !req.headers['content-length']) {
if((req.method === 'DELETE' || req.method === 'OPTIONS')
&& !req.headers['content-length']) {
req.headers['content-length'] = '0';
}
},
Expand Down
13 changes: 11 additions & 2 deletions test/lib-http-proxy-passes-web-incoming-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ var webPasses = require('../lib/http-proxy/passes/web-incoming'),

describe('lib/http-proxy/passes/web.js', function() {
describe('#deleteLength', function() {
it('should change `content-length`', function() {
it('should change `content-length` for DELETE requests', function() {
var stubRequest = {
method: 'DELETE',
headers: {}
};
webPasses.deleteLength(stubRequest, {}, {});
expect(stubRequest.headers['content-length']).to.eql('0');
})
});

it('should change `content-length` for OPTIONS requests', function() {
var stubRequest = {
method: 'OPTIONS',
headers: {}
};
webPasses.deleteLength(stubRequest, {}, {});
expect(stubRequest.headers['content-length']).to.eql('0');
});
});

describe('#timeout', function() {
Expand Down

0 comments on commit 3194d81

Please sign in to comment.