Add transfer-encoding to watchdog env-vars if present

The Content-Type header must be ignored when the Transfer
Encoding is set to "chunked" because the length is unknown

Go sets this to -1 and we pass that onto the user:
https://golang.org/src/net/http/transfer.go

The value of Content_Length is currently set to -1 in this
scenario, however it caused some confusion for at least one
user in issue: #1422.

The Http_Transfer_Encoding value was tested by running the
watchdog on Linux with "env" as the fprocess and an extra
header to "curl"

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2020-01-05 19:05:08 +00:00 committed by Alex Ellis
parent 09b867559d
commit 6a30ce1e36
2 changed files with 9 additions and 4 deletions

View File

@ -38,9 +38,9 @@ Here's how to package your function if you don't want to use the CLI or have exi
Example Dockerfile for an `echo` function:
```
FROM alpine:3.8
FROM alpine:3.11
ADD https://github.com/openfaas/faas/releases/download/0.9.14/fwatchdog /usr/bin
ADD https://github.com/openfaas/faas/releases/download/0.18.10/fwatchdog /usr/bin
RUN chmod +x /usr/bin/fwatchdog
# Define your binary here
@ -134,9 +134,10 @@ The `X-Forwarded-By` header becomes available as `Http_X_Forwarded_By`
* `Http_Method` - GET/POST etc
* `Http_Query` - QueryString value
* `Http_ContentLength` - gives the total content-length of the incoming HTTP request received by the watchdog.
* `Http_ContentLength` and `Http_Content_Length` - gives the total content-length of the incoming HTTP request received by the watchdog, see note below
* `Http_Transfer_Encoding` - only set when provided, if set to `chunked` the Content-Length will be `-1` to show that it does not apply
> This behaviour is enabled by the `cgi_headers` environmental variable which is enabled by default.
> This behaviour is enabled by the `cgi_headers` environmental variable which is enabled (`true`) by default.
Here's an example of a POST request with an additional header and a query-string.

View File

@ -237,6 +237,10 @@ func getAdditionalEnvs(config *WatchdogConfig, r *http.Request, method string) [
envs = append(envs, fmt.Sprintf("Http_ContentLength=%d", r.ContentLength))
envs = append(envs, fmt.Sprintf("Http_Content_Length=%d", r.ContentLength))
if len(r.TransferEncoding) > 0 {
envs = append(envs, fmt.Sprintf("Http_Transfer_Encoding=%s", r.TransferEncoding[0]))
}
if config.writeDebug {
log.Println("Query ", r.URL.RawQuery)
}