openfaas / templates

OpenFaaS Classic templates
https://www.openfaas.com
MIT License
276 stars 228 forks source link

Add raw body support to python3 templates #207

Open viveksyngh opened 4 years ago

viveksyngh commented 4 years ago

Signed-off-by: Vivek Singh vivekkmr45@yahoo.in

Description

Motivation and Context

Which issue(s) this PR fixes

Fixes #

How Has This Been Tested?

This has been tested on my local with kind

faas-cli invoke raw-body-test <<< "Hello"
Handling connection for 8080
Hello

<class 'str'>
➜  templates git:(raw_body) ✗ faas-cli deploy -f raw-body-test.yml --env=RAW_BODY=True
Deploying: raw-body-test.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
Handling connection for 8080

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/raw-body-test

➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-test <<< "Hello"               
Handling connection for 8080
Hello

<class 'str'>
➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-test <<< "Hello"
Handling connection for 8080
b'Hello\n'
<class 'bytes'>
➜  templates git:(raw_body) ✗ faas-cli deploy -f raw-body-debian.yml   
Deploying: raw-body-debian.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
Handling connection for 8080

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/raw-body-debian

➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-debian <<< "Hello"
Handling connection for 8080
Hello

<class 'str'>
➜  templates git:(raw_body) ✗ faas-cli deploy -f raw-body-debian.yml --env=RAW_BODY=True
Deploying: raw-body-debian.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
Handling connection for 8080

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/raw-body-debian

➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-debian <<< "Hello"               
Handling connection for 8080
b'Hello\n'
<class 'bytes'>

Types of changes

Impact to existing users

Checklist:

alexellis commented 4 years ago

Thanks for the PR. Just bear in mind to fill out the template i.e. How Has This Been Tested?

alexellis commented 4 years ago

Need to cross reference with https://github.com/openfaas-incubator/python-flask-template/pull/38

viveksyngh commented 4 years ago

Need to cross reference with openfaas-incubator/python-flask-template#38

This has been handled within is_val function.

jpauwels commented 3 years ago

Hi @alexellis, @viveksyngh

Sorry to hijack this PR, but I opened a similar, but more extensive issue (#205) in May. In it, I proposed opening a PR with my tried-and-tested solution, but since I got no response on the issue, I didn't at the time. I've now created it as #217.

Imho, my solution is less hackish, as it parses standard headers and doesn't require environment variable definition. It also is more extensive in functionality.

I'd be happy to propose similar changes to the flask templates (actually have those running privately too).