functions

The Fool guy's FAAS
git clone git://git.lair.cx/functions
Log | Files | Refs | README

commit 89040caaca1639719e85c85444feba4bafc5f947
parent 1de0e8ffb2ffb58897edfb081e5ac6acc5d2f754
Author: Yongbin Kim <iam@yongbin.kim>
Date:   Tue, 19 Sep 2023 02:27:30 +0900

fix: Fix issue where headers were not being transmitted properly

Signed-off-by: Yongbin Kim <iam@yongbin.kim>

Diffstat:
MDockerfile | 2+-
Mcmd/functions/main.go | 4++--
Mexamples/helloworld/main.go | 5+++++
3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile @@ -22,7 +22,7 @@ RUN go mod verify # Copy the source from the current directory to the Working Directory inside the container COPY . . -RUN go build -v -o /bin/functions ./cmd/functions +RUN go build -v -tags prod -o /bin/functions ./cmd/functions FROM scratch diff --git a/cmd/functions/main.go b/cmd/functions/main.go @@ -205,8 +205,6 @@ func handleStdout(w http.ResponseWriter, stdout io.Reader, wg *sync.WaitGroup, n return } - w.WriteHeader(statusCode) - // Read headers for { line, err := r.ReadString('\n') @@ -239,6 +237,8 @@ func handleStdout(w http.ResponseWriter, stdout io.Reader, wg *sync.WaitGroup, n w.Header().Add(parts[0], parts[1]) } + w.WriteHeader(statusCode) + // Copy the rest of the body _, err = io.Copy(w, r) } diff --git a/examples/helloworld/main.go b/examples/helloworld/main.go @@ -22,6 +22,11 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request) { panic("panic because name is panic") } + if name == "redirect" { + http.Redirect(w, r, "/helloworld?name=redirected", http.StatusFound) + return + } + buf := make([]byte, 0, len(name)+8) buf = append(buf, "Hello, "...) buf = append(buf, name...)