CodeGenieApp / CodeGenieApp/serverless-express

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

オープン
#685 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
5.3k
フォーク
676
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used [patch-package](https://github.com/ds300/patch-package) to patch `@vendia/serverless-express@4.12.6` for the project I'm working on.

My issue is with apollo-server as described in more detail [here](https://github.com/apollographql/apollo-server/issues/7289). However, other people experience a similar issue with ALB such as the case described [here](https://github.com/CodeGenieApp/serverless-express/issues/563). 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](https://github.com/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
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](https://github.com/ds300/patch-package/issues/296).

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、言及されている4つのイベントソースファイル、api-gateway-v2.js、lambda-edge.js、http-function-runtime-v3.js、utils.jsを読みます。これらのContent-Lengthの処理を提供されたdiffと比較し、影響を受ける各ヘッダーが期待されるstring型になっていることを確認してください。このissueには実行するテストファイルがありません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
aws, azure, javascript, node.js
領域
api, backend, cloud
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。