@@ -21,6 +21,7 @@ type Invoker struct {
2121 PrintResponse bool
2222 Client * http.Client
2323 GatewayURL string
24+ ContentType string
2425 Responses chan InvokerResponse
2526}
2627
@@ -37,11 +38,12 @@ type InvokerResponse struct {
3738}
3839
3940// NewInvoker constructs an Invoker instance
40- func NewInvoker (gatewayURL string , client * http.Client , printResponse bool ) * Invoker {
41+ func NewInvoker (gatewayURL string , client * http.Client , contentType string , printResponse bool ) * Invoker {
4142 return & Invoker {
4243 PrintResponse : printResponse ,
4344 Client : client ,
4445 GatewayURL : gatewayURL ,
46+ ContentType : contentType ,
4547 Responses : make (chan InvokerResponse ),
4648 }
4749}
@@ -67,7 +69,7 @@ func (i *Invoker) InvokeWithContext(ctx context.Context, topicMap *TopicMap, top
6769 gwURL := fmt .Sprintf ("%s/%s" , i .GatewayURL , matchedFunction )
6870 reader := bytes .NewReader (* message )
6971
70- body , statusCode , header , doErr := invokefunction (ctx , i .Client , gwURL , reader )
72+ body , statusCode , header , doErr := invokefunction (ctx , i .Client , gwURL , i . ContentType , reader )
7173
7274 if doErr != nil {
7375 i .Responses <- InvokerResponse {
@@ -88,7 +90,7 @@ func (i *Invoker) InvokeWithContext(ctx context.Context, topicMap *TopicMap, top
8890 }
8991}
9092
91- func invokefunction (ctx context.Context , c * http.Client , gwURL string , reader io.Reader ) (* []byte , int , * http.Header , error ) {
93+ func invokefunction (ctx context.Context , c * http.Client , gwURL , contentType string , reader io.Reader ) (* []byte , int , * http.Header , error ) {
9294
9395 httpReq , err := http .NewRequest (http .MethodPost , gwURL , reader )
9496 if err != nil {
@@ -100,6 +102,10 @@ func invokefunction(ctx context.Context, c *http.Client, gwURL string, reader io
100102 defer httpReq .Body .Close ()
101103 }
102104
105+ if contentType != "" {
106+ httpReq .Header .Set ("Content-Type" , contentType )
107+ }
108+
103109 var body * []byte
104110
105111 res , doErr := c .Do (httpReq )
0 commit comments