diff --git a/handler_utils/debug.go b/handler_utils/debug.go index 86aa9a5bcad7266c0b8c2e22b9b6ff49b8b4c432..6ab3bba7d3f0ec691c94388dc1990177b6d6e992 100644 --- a/handler_utils/debug.go +++ b/handler_utils/debug.go @@ -3,6 +3,7 @@ package handler_utils import ( "bytes" "context" + "encoding/base64" "encoding/json" "fmt" "io" @@ -72,9 +73,22 @@ func ServeHTTPFunctions(ctx context.Context, lambdaHandler lambda.Handler, w htt w.Header().Set(key, value.(string)) } - w.Header().Set("Content-Type", "application/json") + if w.Header().Get("Content-Type") == "" { + w.Header().Set("Content-Type", "application/json") + } w.WriteHeader(int(response["statusCode"].(float64))) + + if response["isBase64Encoded"].(bool) { + decoded, err := base64.StdEncoding.DecodeString(response["body"].(string)) + if err != nil { + panic(err) + } + + _, _ = w.Write(decoded) + return + } + _, _ = io.WriteString(w, response["body"].(string)) }