Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: content-length was not matching the body after an array to string conversion #130

17 changes: 16 additions & 1 deletion index.js
Expand Up @@ -82,9 +82,18 @@ function forwardResponseToApiGateway(server, response, context) {
const contentType = getContentType({ contentTypeHeader: headers['content-type'] })
const isBase64Encoded = isContentTypeBinaryMimeType({ contentType, binaryMimeTypes: server._binaryTypes })
const body = bodyBuffer.toString(isBase64Encoded ? 'base64' : 'utf8')

// Set the proper body length for base64 encoded responses
if(isBase64Encoded && typeof headers['content-length'] !== "undefined") {
headers['content-length'] = body.length.toString()
}

const successResponse = {statusCode, body, headers, isBase64Encoded}

context.succeed(successResponse)
context.succeed(successResponse);
if (context.local && server && server.close) {
server.close();
}
})
}

Expand All @@ -98,6 +107,9 @@ function forwardConnectionErrorResponseToApiGateway(server, error, context) {
}

context.succeed(errorResponse)
if (context.local && server && server.close) {
server.close();
}
}

function forwardLibraryErrorResponseToApiGateway(server, error, context) {
Expand All @@ -110,6 +122,9 @@ function forwardLibraryErrorResponseToApiGateway(server, error, context) {
}

context.succeed(errorResponse)
if (context.local && server && server.close) {
server.close();
}
}

function forwardRequestToNodeServer(server, event, context) {
Expand Down