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
Branches
Tags
1 merge request!47Add support for base64 encoded response body in ServeHTTPFunctions
......@@ -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))
}
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))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment