This repository was archived by the owner on Aug 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33package core
44
55import (
6+ "bytes"
67 "encoding/base64"
78 "errors"
89 "net/http"
@@ -17,7 +18,7 @@ const defaultStatusCode = -1
1718// necessary to return an events.APIGatewayProxyResponse object
1819type ProxyResponseWriter struct {
1920 headers http.Header
20- body [] byte
21+ body bytes. Buffer
2122 status int
2223}
2324
@@ -41,12 +42,11 @@ func (r *ProxyResponseWriter) Header() http.Header {
4142// was set before with the WriteHeader method it sets the status
4243// for the response to 200 OK.
4344func (r * ProxyResponseWriter ) Write (body []byte ) (int , error ) {
44- r .body = body
4545 if r .status == - 1 {
4646 r .status = http .StatusOK
4747 }
4848
49- return len ( body ), nil
49+ return ( & r . body ). Write ( body )
5050}
5151
5252// WriteHeader sets a status code for the response. This method is used
@@ -67,10 +67,12 @@ func (r *ProxyResponseWriter) GetProxyResponse() (events.APIGatewayProxyResponse
6767 var output string
6868 isBase64 := false
6969
70- if utf8 .Valid (r .body ) {
71- output = string (r .body )
70+ bb := (& r .body ).Bytes ()
71+
72+ if utf8 .Valid (bb ) {
73+ output = string (bb )
7274 } else {
73- output = base64 .StdEncoding .EncodeToString (r . body )
75+ output = base64 .StdEncoding .EncodeToString (bb )
7476 isBase64 = true
7577 }
7678
You can’t perform that action at this time.
0 commit comments