diff --git a/trigger/rest/README.md b/trigger/rest/README.md index e70ac6a4..a2bce98d 100644 --- a/trigger/rest/README.md +++ b/trigger/rest/README.md @@ -38,10 +38,11 @@ flogo install github.com/project-flogo/contrib/trigger/rest | content | any | The content of the request ### Reply: -| Name | Type | Description -|:--- | :--- | :--- -| code | int | The http code to reply with -| data | any | The data to reply with +| Name | Type | Description +|:--- | :--- | :--- +| code | int | The http code to reply with +| data | any | The data to reply with +|headers| params | The HTTP response headers ## Example Configurations diff --git a/trigger/rest/descriptor.json b/trigger/rest/descriptor.json index 31a02310..15639452 100644 --- a/trigger/rest/descriptor.json +++ b/trigger/rest/descriptor.json @@ -1,7 +1,7 @@ { "name": "flogo-rest", "type": "flogo:trigger", - "version": "0.9.0", + "version": "0.9.1", "title": "Receive HTTP Message", "description": "Simple REST Trigger", "homepage": "https://github.com/project-flogo/contrib/tree/master/trigger/rest", @@ -65,6 +65,11 @@ "name": "data", "type": "any", "description": "The data to reply with" + }, + { + "name": "headers", + "type": "params", + "description": "The HTTP response headers" } ], "handler": { diff --git a/trigger/rest/go.mod b/trigger/rest/go.mod index 151dab07..00c2bce2 100644 --- a/trigger/rest/go.mod +++ b/trigger/rest/go.mod @@ -2,6 +2,8 @@ module github.com/project-flogo/contrib/trigger/rest require ( github.com/julienschmidt/httprouter v1.2.0 + github.com/pkg/errors v0.8.1 // indirect github.com/project-flogo/core v0.9.2 github.com/stretchr/testify v1.3.0 ) + diff --git a/trigger/rest/go.sum b/trigger/rest/go.sum index 81177702..6470562d 100644 --- a/trigger/rest/go.sum +++ b/trigger/rest/go.sum @@ -6,8 +6,7 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/project-flogo/core v0.9.0 h1:/iR4m5L0zj5SuqLtDDZIRyvrvG8TxwxdM0n8ZURo1I4= -github.com/project-flogo/core v0.9.0/go.mod h1:QGWi7TDLlhGUaYH3n/16ImCuulbEHGADYEXyrcHhX7U= +github.com/project-flogo/core v0.9.2 h1:1j7d8e6ivwnhyRudeTRIZlr2XCNa+SERrmcrzKswr0Y= github.com/project-flogo/core v0.9.2/go.mod h1:QGWi7TDLlhGUaYH3n/16ImCuulbEHGADYEXyrcHhX7U= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/trigger/rest/metadata.go b/trigger/rest/metadata.go index deed7017..bcc6e379 100644 --- a/trigger/rest/metadata.go +++ b/trigger/rest/metadata.go @@ -22,12 +22,12 @@ type Output struct { Headers map[string]string `md:"headers"` // The HTTP header parameters Content interface{} `md:"content"` // The content of the request Method string `md:"method"` // The HTTP method used for the request - } type Reply struct { - Code int `md:"code"` // The http code to reply with - Data interface{} `md:"data"` // The data to reply with + Code int `md:"code"` // The http code to reply with + Data interface{} `md:"data"` // The data to reply with + Headers map[string]string `md:"headers"` // The HTTP response headers } func (o *Output) ToMap() map[string]interface{} { @@ -66,8 +66,9 @@ func (o *Output) FromMap(values map[string]interface{}) error { func (r *Reply) ToMap() map[string]interface{} { return map[string]interface{}{ - "code": r.Code, - "data": r.Data, + "code": r.Code, + "data": r.Data, + "headers": r.Headers, } } @@ -79,6 +80,10 @@ func (r *Reply) FromMap(values map[string]interface{}) error { return err } r.Data, _ = values["data"] + r.Headers, err = coerce.ToParams(values["headers"]) + if err != nil { + return err + } return nil } diff --git a/trigger/rest/trigger.go b/trigger/rest/trigger.go index 74b6799c..8faf7136 100644 --- a/trigger/rest/trigger.go +++ b/trigger/rest/trigger.go @@ -268,6 +268,13 @@ func newActionHandler(rt *Trigger, method string, handler trigger.Handler) httpr return } + // add response headers + if len(reply.Headers) > 0 { + for key, value := range reply.Headers { + w.Header().Add(key, value) + } + } + if reply.Data != nil { if reply.Code == 0 {