openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
794 stars 226 forks source link

invoke function through faas-cli lead to an extra newline appended to the input #771

Closed t83714 closed 4 years ago

t83714 commented 4 years ago

If you invoke your function in the following way:

echo "123" | faas-cli invokve my-function

The input string received by the function (Tested using ofwatch HTTP mode, so here talk about http body) is 123\n rather than 123.

It can't be the issue of the openfaas gateway as if you invoke by sending a POST request directly to gateway:

POST http://[gateway ip]:8080/function/my-function
With Body: 123

you won't get the extra newline \n

Expected Behaviour

No extra newline is appended to the original input

Current Behaviour

An extra newline is appended to the original input if invoke the function using faas-cli only

Possible Solution

N/A

Context

The extra newline \n introduced pollute the input and create bugs.

You can't simply trim the string input either --- as the invocation through gateway won't introduce an extra newline.

Your Environment

The version I used:

CLI:
 commit:  ea687659ecf14931a29be46c4d2866899d36c282
 version: 0.11.8

Gateway
 uri:     http://127.0.0.1:8080
 version: 0.18.10
 sha:     80b6976c106370a7081b2f8e9099a6ea9638e1f3
 commit:  Update Golang versions to 1.12

Provider
 name:          openfaas-operator
 orchestration: kubernetes
 version:       0.14.1 
 sha:           e747b6ace86bc54184d899fa10cf46dada331af1
alexellis commented 4 years ago

Hi @t83714 thank you for your interest.

faas-cli invoke does not add newlines, the echo command in bash adds a new-line, therefore you may prefer to use echo -n to prevent that newline, or to use some other command or binary as the input i.e. uname | faas-cli invoke.

If you need further help, please use Slack for technical support issues.

Alex

alexellis commented 4 years ago

/msg: slack

derek[bot] commented 4 years ago

-- Join Slack to connect with the community https://docs.openfaas.com/community

t83714 commented 4 years ago

Thanks @alexellis 👍