From b216911fa5278afa8f64d78a954ffc268781a4a2 Mon Sep 17 00:00:00 2001
From: "daniel.naude" <danieln@bob.co.za>
Date: Tue, 12 Mar 2024 15:33:03 +0200
Subject: [PATCH] Add support for base64 encoded response body in
 ServeHTTPFunctions

---
 handler_utils/debug.go | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/handler_utils/debug.go b/handler_utils/debug.go
index 86aa9a5..6ab3bba 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))
 }
 
-- 
GitLab