diff --git a/bindings/rabbitmq/rabbitmq.go b/bindings/rabbitmq/rabbitmq.go index e10f7422f3..d4ae6bb75a 100644 --- a/bindings/rabbitmq/rabbitmq.go +++ b/bindings/rabbitmq/rabbitmq.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "math" + "net/url" "reflect" "strconv" "sync" @@ -464,8 +465,20 @@ func (r *RabbitMQ) handleMessage(ctx context.Context, handler bindings.Handler, r.logger.Info("Input binding channel closed") return } + + metadata := make(map[string]string) + // Passthrough any custom metadata to the handler. + for k, v := range d.Headers { + if s, ok := v.(string); ok { + // Escape the key and value to ensure they are valid URL query parameters. + // This is necessary for them to be sent as HTTP Metadata. + metadata[url.QueryEscape(k)] = url.QueryEscape(s) + } + } + _, err := handler(ctx, &bindings.ReadResponse{ - Data: d.Body, + Data: d.Body, + Metadata: metadata, }) if err != nil { ch.Nack(d.DeliveryTag, false, true)