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

Content-Length header is a number instead of a string which causes issues downstream #685

Open
colin-oos opened this issue Jul 29, 2024 · 0 comments

Comments

@colin-oos
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @vendia/[email protected] for the project I'm working on.

My issue is with apollo-server as described in more detail here. However, other people experience a similar issue with ALB such as the case described here. These issues have existed for a long time so I figured it is about time this gets addressed. People have been forced to switch to H4ad/serverless-adapter instead in the meantime.

I will be putting up a PR for this issue shortly and will link to this issue. Until then, here is the diff that solved my problem:

diff --git a/node_modules/@vendia/serverless-express/src/event-sources/aws/api-gateway-v2.js b/node_modules/@vendia/serverless-express/src/event-sources/aws/api-gateway-v2.js
index 56896c1..c2136cf 100644
--- a/node_modules/@vendia/serverless-express/src/event-sources/aws/api-gateway-v2.js
+++ b/node_modules/@vendia/serverless-express/src/event-sources/aws/api-gateway-v2.js
@@ -33,7 +33,7 @@ function getRequestValuesFromApiGatewayEvent ({ event }) {
   if (event.body) {
     body = getEventBody({ event })
     const isBase64Encoded = event.isBase64Encoded
-    headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8')
+    headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8').toString()
   }
 
   return {
diff --git a/node_modules/@vendia/serverless-express/src/event-sources/aws/lambda-edge.js b/node_modules/@vendia/serverless-express/src/event-sources/aws/lambda-edge.js
index 217fbe9..ebc135e 100644
--- a/node_modules/@vendia/serverless-express/src/event-sources/aws/lambda-edge.js
+++ b/node_modules/@vendia/serverless-express/src/event-sources/aws/lambda-edge.js
@@ -28,7 +28,7 @@ function getRequestValuesFromLambdaEdgeEvent ({ event }) {
       body: requestBodyObject.data,
       isBase64Encoded
     })
-    headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8')
+    headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8').toString()
   }
 
   const path = url.format({
diff --git a/node_modules/@vendia/serverless-express/src/event-sources/azure/http-function-runtime-v3.js b/node_modules/@vendia/serverless-express/src/event-sources/azure/http-function-runtime-v3.js
index c5c887e..57c464a 100644
--- a/node_modules/@vendia/serverless-express/src/event-sources/azure/http-function-runtime-v3.js
+++ b/node_modules/@vendia/serverless-express/src/event-sources/azure/http-function-runtime-v3.js
@@ -17,7 +17,7 @@ function getRequestValuesFromHttpFunctionEvent ({ event }) {
 
   const body = context.rawBody
   if (body) {
-    headers['content-length'] = Buffer.byteLength(body, 'utf8')
+    headers['content-length'] = Buffer.byteLength(body, 'utf8').toString()
   }
 
   return {
diff --git a/node_modules/@vendia/serverless-express/src/event-sources/utils.js b/node_modules/@vendia/serverless-express/src/event-sources/utils.js
index c5537e1..accd919 100644
--- a/node_modules/@vendia/serverless-express/src/event-sources/utils.js
+++ b/node_modules/@vendia/serverless-express/src/event-sources/utils.js
@@ -41,7 +41,7 @@ function getRequestValuesFromEvent ({
   if (event.body) {
     body = getEventBody({ event })
     const { isBase64Encoded } = event
-    headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8')
+    headers['content-length'] = Buffer.byteLength(body, isBase64Encoded ? 'base64' : 'utf8').toString()
   }
 
   const remoteAddress = (event && event.requestContext && event.requestContext.identity && event.requestContext.identity.sourceIp) || ''

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant