Skip to content
Snippets Groups Projects

Add support for base64 encoded response body in ServeHTTPFunctions

1 file
+ 15
1
Compare changes
  • Side-by-side
  • Inline
+ 15
1
@@ -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))
}
Loading