File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 3
3
package core
4
4
5
5
import (
6
+ "bytes"
6
7
"encoding/base64"
7
8
"errors"
8
9
"net/http"
@@ -17,7 +18,7 @@ const defaultStatusCode = -1
17
18
// necessary to return an events.APIGatewayProxyResponse object
18
19
type ProxyResponseWriter struct {
19
20
headers http.Header
20
- body [] byte
21
+ body bytes. Buffer
21
22
status int
22
23
}
23
24
@@ -41,12 +42,11 @@ func (r *ProxyResponseWriter) Header() http.Header {
41
42
// was set before with the WriteHeader method it sets the status
42
43
// for the response to 200 OK.
43
44
func (r * ProxyResponseWriter ) Write (body []byte ) (int , error ) {
44
- r .body = body
45
45
if r .status == - 1 {
46
46
r .status = http .StatusOK
47
47
}
48
48
49
- return len ( body ), nil
49
+ return ( & r . body ). Write ( body )
50
50
}
51
51
52
52
// WriteHeader sets a status code for the response. This method is used
@@ -67,10 +67,12 @@ func (r *ProxyResponseWriter) GetProxyResponse() (events.APIGatewayProxyResponse
67
67
var output string
68
68
isBase64 := false
69
69
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 )
72
74
} else {
73
- output = base64 .StdEncoding .EncodeToString (r . body )
75
+ output = base64 .StdEncoding .EncodeToString (bb )
74
76
isBase64 = true
75
77
}
76
78
You can’t perform that action at this time.
0 commit comments