Skip to content
Snippets Groups Projects
Commit b216911f authored by Daniel Naude's avatar Daniel Naude
Browse files

Add support for base64 encoded response body in ServeHTTPFunctions

parent 86c68a2a
No related branches found
No related tags found
1 merge request!47Add support for base64 encoded response body in ServeHTTPFunctions
...@@ -3,6 +3,7 @@ package handler_utils ...@@ -3,6 +3,7 @@ package handler_utils
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
...@@ -72,9 +73,22 @@ func ServeHTTPFunctions(ctx context.Context, lambdaHandler lambda.Handler, w htt ...@@ -72,9 +73,22 @@ func ServeHTTPFunctions(ctx context.Context, lambdaHandler lambda.Handler, w htt
w.Header().Set(key, value.(string)) w.Header().Set(key, value.(string))
} }
if w.Header().Get("Content-Type") == "" {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
}
w.WriteHeader(int(response["statusCode"].(float64))) 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)) _, _ = io.WriteString(w, response["body"].(string))
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment