Skip to content

Commit bbfaf78

Browse files
committed
feat: read until body EOF
1 parent 0b4e711 commit bbfaf78

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

handler/apigwv1.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"encoding/base64"
99
"github.com/aws/aws-lambda-go/events"
10+
"io"
1011
"net/http"
1112
"net/url"
1213
"strconv"
@@ -116,7 +117,11 @@ func handleApiGwV1(ctx context.Context, event events.APIGatewayProxyRequest, ada
116117
return def, err
117118
}
118119

119-
b := w.body.Bytes()
120+
b, err := io.ReadAll(&w.body)
121+
if err != nil {
122+
var def events.APIGatewayProxyResponse
123+
return def, err
124+
}
120125

121126
if !w.contentTypeSet {
122127
w.res.Headers["Content-Type"] = http.DetectContentType(b)

handler/apigwv2.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"encoding/base64"
99
"github.com/aws/aws-lambda-go/events"
10+
"io"
1011
"net/http"
1112
"strconv"
1213
"strings"
@@ -107,7 +108,11 @@ func handleApiGwV2(ctx context.Context, event events.APIGatewayV2HTTPRequest, ad
107108
return def, err
108109
}
109110

110-
b := w.body.Bytes()
111+
b, err := io.ReadAll(&w.body)
112+
if err != nil {
113+
var def events.APIGatewayV2HTTPResponse
114+
return def, err
115+
}
111116

112117
if !w.contentTypeSet {
113118
w.res.Headers["Content-Type"] = http.DetectContentType(b)

0 commit comments

Comments
 (0)