Skip to content

Commit ef933c8

Browse files
committed
Copy upstream response into http writer
As an optimization, the response body for the HTTP runner can stream data back, instead of buffering it all in memory and then sending it in one shot. This change means replacing an io.ReadAll with an io.Copy, as a result, it's possible that some callers will no longer receive a content-length, but a stream of data with a length of -1. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent a6a3f4c commit ef933c8

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Dockerfile

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM scratch as cache
1+
FROM scratch AS cache
22

33
COPY bin .
44

5-
FROM scratch as ship
5+
FROM scratch AS ship
66

77
ARG TARGETPLATFORM
88
ARG BUILDPLATFORM
@@ -11,4 +11,11 @@ ARG TARGETARCH
1111

1212
COPY --from=cache /fwatchdog-$TARGETARCH ./fwatchdog
1313

14+
LABEL org.label-schema.license="MIT" \
15+
org.label-schema.vcs-url="https://github.com/openfaas/of-watchdog" \
16+
org.label-schema.vcs-type="Git" \
17+
org.label-schema.name="openfaas/of-watchdog" \
18+
org.label-schema.vendor="openfaas" \
19+
org.label-schema.docker.schema-version="1.0"
20+
1421
ENTRYPOINT ["/fwatchdog"]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ Example usage for testing:
7878
* Forward to an Nginx container:
7979

8080
```
81-
$ go build ; mode=http port=8081 fprocess="docker run -p 80:80 --name nginx -t nginx" upstream_url=http://127.0.0.1:80 ./of-watchdog
81+
$ go build && mode=http port=8081 fprocess="docker run -p 80:80 --name nginx -t nginx" upstream_url=http://127.0.0.1:80 ./of-watchdog
8282
```
8383

8484
* Forward to a Node.js / Express.js hello-world app:
8585

8686
```
87-
$ go build ; mode=http port=8081 fprocess="node expressjs-hello-world.js" upstream_url=http://127.0.0.1:3000 ./of-watchdog
87+
$ go build && mode=http port=8081 fprocess="node expressjs-hello-world.js" upstream_url=http://127.0.0.1:3000 ./of-watchdog
8888
```
8989

9090
Cons:

executor/http_runner.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,9 @@ func (f *HTTPFunctionRunner) Run(req FunctionRequest, contentLength int64, r *ht
183183
if res.Body != nil {
184184
defer res.Body.Close()
185185

186-
bodyBytes, bodyErr := io.ReadAll(res.Body)
187-
if bodyErr != nil {
188-
log.Println("read body err", bodyErr)
186+
if _, err := io.Copy(w, res.Body); err != nil {
187+
log.Printf("Error copying response body: %s", err)
189188
}
190-
w.Write(bodyBytes)
191189
}
192190

193191
// Exclude logging for health check probes from the kubelet which can spam

0 commit comments

Comments
 (0)