openfaas / connector-sdk

SDK for connecting events to functions
MIT License
54 stars 25 forks source link

[Feature Request] Allow to set custom header fields #52

Closed JonasDoe closed 3 years ago

JonasDoe commented 3 years ago

At the moment there's no possibility to add HTTP header fields to the invoke function. I've found this issue addressing the same feature, but it was solved in a way I don't understand (afaik the http package does not allow you to set header fields via the Context) and probably solved only his own issue (the tracing). Additionally, there was already a PR with a possible solution, but it died halfway.

Our case: We're working with CloudEvents and need to set the Content-Type to application/cloudevents+json to make relating sdk (https://github.com/cloudevents/sdk-go) at the function work properly.

I think the custom header fields could be set in the ControllerConfig, but maybe that's to general, or passed as an argument for Invoke and InvokeWithContext methods. Another option to keep the method's signature lean would be to support custom header fields in the Context passed by InvokeWithContext (a bit diverting though), or establish some kind of InvocationOptions type as an argument which holds custom headers and maybe other settings in future.

JonasDoe commented 3 years ago

I'ld be willing to provide a new PR, but in that case I'ld need a preference about how to implement that. In ControllerConfig? As an argument? In the Context? With InvocationOptions? In a completely different way?

rshlapak-altair commented 3 years ago

This feature can solve another issue: Payload is not passed from connector to function. Event tester example doesn't work properly - body is always empty in called function.

I made it working by adding next line in invoker.go:90 (func invokefunction) httpReq.Header.Set("Content-Type", "text/plain")

Any advices?

mathieuforest commented 3 years ago

@rshlapak-altair same issue here.

alexellis commented 3 years ago

Payload is not passed from connector to function. Event tester example doesn't work properly - body is always empty in called function.

Please raise your own issue and detail everything you're using. Including the template.