Skip to content

Commit 3194d81

Browse files
committed
Merge pull request #742 from jugglinmike/option-content-length
Set `Content-Length` header for OPTIONS requests
2 parents aba505d + 8a24a1e commit 3194d81

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/http-proxy/passes/web-incoming.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ web_o = Object.keys(web_o).map(function(pass) {
2929
*/
3030

3131
function deleteLength(req, res, options) {
32-
if(req.method === 'DELETE' && !req.headers['content-length']) {
32+
if((req.method === 'DELETE' || req.method === 'OPTIONS')
33+
&& !req.headers['content-length']) {
3334
req.headers['content-length'] = '0';
3435
}
3536
},

test/lib-http-proxy-passes-web-incoming-test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ var webPasses = require('../lib/http-proxy/passes/web-incoming'),
55

66
describe('lib/http-proxy/passes/web.js', function() {
77
describe('#deleteLength', function() {
8-
it('should change `content-length`', function() {
8+
it('should change `content-length` for DELETE requests', function() {
99
var stubRequest = {
1010
method: 'DELETE',
1111
headers: {}
1212
};
1313
webPasses.deleteLength(stubRequest, {}, {});
1414
expect(stubRequest.headers['content-length']).to.eql('0');
15-
})
15+
});
16+
17+
it('should change `content-length` for OPTIONS requests', function() {
18+
var stubRequest = {
19+
method: 'OPTIONS',
20+
headers: {}
21+
};
22+
webPasses.deleteLength(stubRequest, {}, {});
23+
expect(stubRequest.headers['content-length']).to.eql('0');
24+
});
1625
});
1726

1827
describe('#timeout', function() {

0 commit comments

Comments
 (0)