openfaas / connector-sdk

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

controller: add content type option to send in the headers when invoking a function #59

Closed cpanato closed 3 years ago

cpanato commented 3 years ago

Description

add content-type option to send in the headers when invoking a function

Motivation and Context

How Has This Been Tested?

To test this you will need to do:

package function

import (
    "fmt"
    "log"
    "os"
)

// Handle a serverless request
func Handle(req []byte) string {
        log.Printf("Content Type: %s", os.Getenv("Http_Content_Type"))
    return fmt.Sprintf("Hello! your Content-Type is: %s", os.Getenv("Http_Content_Type"))
}

and in the stack.yaml definition add the annotation

annotations:
   topic: "vm.powered.on"
    config := &types.ControllerConfig{
        RebuildInterval:         time.Millisecond * 1000,
        GatewayURL:              "http://127.0.0.1:8080",
        PrintResponse:           true,
        PrintResponseBody:       true,
        AsyncFunctionInvocation: false,
        ContentType:             "application/json",
    }

Types of changes

Checklist:

Fixes: https://github.com/openfaas/connector-sdk/issues/58