Skip to content

Commit

Permalink
Updates AWS.APIGateway.getSdk to return body as a buffer
Browse files Browse the repository at this point in the history
 instead of a utf-8 string

fixes #815
  • Loading branch information
chrisradek committed Apr 5, 2016
1 parent 266875c commit c745978
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/services/apigateway.js
Expand Up @@ -16,6 +16,19 @@ AWS.util.update(AWS.APIGateway.prototype, {
*/
setupRequestListeners: function setupRequestListeners(request) {
request.addListener('build', this.setAcceptHeader);
if (request.operation === 'getSdk') {
request.addListener('extractData', this.useRawPayload);
}
},

useRawPayload: function useRawPayload(resp) {
var req = resp.request;
var operation = req.operation;
var rules = req.service.api.operations[operation].output || {};
if (rules.payload) {
var body = resp.httpResponse.body;
resp.data[rules.payload] = body;
}
}
});

11 changes: 10 additions & 1 deletion test/services/apigateway.spec.coffee
@@ -1,5 +1,6 @@
helpers = require('../helpers')
AWS = helpers.AWS
Buffer = AWS.util.Buffer

describe 'AWS.APIGateway', ->
apigateway = null
Expand All @@ -19,4 +20,12 @@ describe 'AWS.APIGateway', ->
req = build('createApiKey', {})
expect(req.headers['Accept']).to.equal('application/json')
req = build('updateApiKey', apiKey: 'apiKey')
expect(req.headers['Accept']).to.equal('application/json')
expect(req.headers['Accept']).to.equal('application/json')

describe 'getSdk', ->
it 'returns the raw payload as the body', (done) ->
body = new Buffer('∂ƒ©∆')
helpers.mockHttpResponse 200, {}, body
apigateway.getSdk (err, data) ->
expect(data.body).to.eql(body)
done()

0 comments on commit c745978

Please sign in to comment.