openfaas / templates

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

Support binary payloads and responses, and non-UTF8 string payloads for Python functions #205

Open jpauwels opened 4 years ago

jpauwels commented 4 years ago

The Python templates currently don't support binary payloads and responses, whereas other templates do (e.g. image-handling functions in store). Much like #203 and #159 for Java, it would be nice to add this capability to the Python templates. Additionally, string payloads are assumed to be UTF-8 encoded, even if content-type signals differently.

Expected Behaviour

When passing binary payload, don't decode to string. When passing string payload, respect content-type encoding. When returning binary file, don't encode as string.

Current Behaviour

UnicodeDecodeError when passing binary payload, incorrect decoding when passing non-UTF-8 string payload. Binary responses get stringified.

Possible Solution

I've got this fixed and working for more than a year in my custom template, happy to send a PR

Steps to Reproduce (for bugs)

Context

Using audio files as payload

Your Environment