diff --git a/.changes/next-release/bugfix-Http-9b51f306.json b/.changes/next-release/bugfix-Http-9b51f306.json new file mode 100644 index 0000000000..80036dd568 --- /dev/null +++ b/.changes/next-release/bugfix-Http-9b51f306.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "Http", + "description": "skip addition of content length 0 header for GET etc. bodyless requests" +} \ No newline at end of file diff --git a/lib/event_listeners.js b/lib/event_listeners.js index 053ff91ebd..870db3b65a 100644 --- a/lib/event_listeners.js +++ b/lib/event_listeners.js @@ -188,7 +188,10 @@ AWS.EventListeners = { if (req.httpRequest.headers['Content-Length'] === undefined) { try { var length = AWS.util.string.byteLength(req.httpRequest.body); - req.httpRequest.headers['Content-Length'] = length; + var method = req.httpRequest.method; + if (['GET', 'DELETE', 'TRACE', 'OPTIONS', 'HEAD'].indexOf(method) === -1 || length > 0) { + req.httpRequest.headers['Content-Length'] = length; + } } catch (err) { if (payloadMember && payloadMember.isStreaming) { if (payloadMember.requiresLength) { diff --git a/test/event_listeners.spec.js b/test/event_listeners.spec.js index 8efab10fde..0db6342894 100644 --- a/test/event_listeners.spec.js +++ b/test/event_listeners.spec.js @@ -240,6 +240,18 @@ return sendRequest(body).httpRequest.headers['Content-Length']; }; + describe('when request is GET or other bodyless method', function() { + it('should skip adding content-length header', function() { + var service = new FooService(); + var req = service.get({}); + + req.runTo('sign', function(err) { + expect('Content-Length' in req.httpRequest.headers).to.equal(false); + expect(!err).to.equal(true); + }); + }); + }); + describe('when using unsigned authtype', function() { it('when payload is a buffer', function() { var service = new FooService(); diff --git a/test/foo-service.fixture.js b/test/foo-service.fixture.js index d6550fa9f3..5b291269e5 100644 --- a/test/foo-service.fixture.js +++ b/test/foo-service.fixture.js @@ -15,6 +15,12 @@ var model = { 'uid': 'foo-2018-06-13' }, 'operations': { + 'Get': { + 'http': { + 'method': 'GET', + 'requestUri': '/' + } + }, 'PutStream': { 'http': { 'method': 'PUT',