Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty print json payloads in the printer function. #8

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

welteki
Copy link
Member

@welteki welteki commented Dec 15, 2023

Description

Update the printer function to support pretty printing of json payloads.

If the env variable RAW=true it will print the raw payload.

How has this been tested

Deployed the printer function:

SERVER=ttl.sh OWNER=welteki faas-cli up --filter printer

Invoked the function with a json payload:

curl -i $OPENFAAS_URL/function/printer \
  -d '{ "foo": "bar", "greeting": "hello" }' \
  -H 'Content-Type: application/json'

Verified the logs to see the payload was printed correctly:

2023-12-15T17:26:00Z User-Agent=[curl/7.81.0]
2023-12-15T17:26:00Z Accept-Encoding=[gzip]
2023-12-15T17:26:00Z X-Forwarded-Host=[gw.exit.welteki.dev]
2023-12-15T17:26:00Z X-Forwarded-Proto=[https]
2023-12-15T17:26:00Z X-Start-Time=[1702661160444470811]
2023-12-15T17:26:00Z Accept=[*/*]
2023-12-15T17:26:00Z X-Forwarded-For=[94.105.108.156, 127.0.0.1]
2023-12-15T17:26:00Z X-Forwarded-Uri=[/function/printer]
2023-12-15T17:26:00Z Content-Type=[application/json]
2023-12-15T17:26:00Z X-Call-Id=[dc321b80-f5d8-4d9f-adea-5f23823abf07]
2023-12-15T17:26:00Z X-Inlets-Id=[303f46d3442a456892f74d55d51debb9]
2023-12-15T17:26:00Z 
2023-12-15T17:26:00Z {
2023-12-15T17:26:00Z     "foo": "bar",
2023-12-15T17:26:00Z     "greeting": "hello"
2023-12-15T17:26:00Z }

Verified the raw payload is printed when the env variable RAW=true
Verified the raw payload is printed if the request does not set the header Content-Type: application/json:

curl -i $OPENFAAS_URL/function/printer \
  -d '{ "foo": "bar", "greeting": "hello" }'

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
@alexellis alexellis merged commit 0cd9790 into openfaas:master Dec 15, 2023
1 check failed
@welteki welteki deleted the pretty-printing branch December 16, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants