Compare commits

...

16 Commits

Author SHA1 Message Date
63ae848043 Merge pull request 'add tls headers' (#170) from tls_header into v3
Reviewed-on: #170
2023-08-03 10:43:47 +03:00
4d378bbd51 add tls headers
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-03 10:43:33 +03:00
60d165f907 add tls headers
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-03 10:42:54 +03:00
5a37de7d74 Merge pull request 'handler/swagger: initial import' (#169) from swagger into v3
Reviewed-on: #169
2023-06-18 17:29:16 +03:00
c7d8b6a3a4 handler/swagger: initial import
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-06-18 17:28:29 +03:00
cd3e2526b4 Merge pull request 'fix query param struct filling' (#167) from matchesfix into v3
Reviewed-on: #167
2023-05-29 12:27:16 +03:00
10ae1741fc fix query param struct filling
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-29 12:26:56 +03:00
ca6cea861f Merge pull request 'add scheme to metadata' (#165) from scheme-v3 into v3
Reviewed-on: #165
2023-05-19 23:25:59 +03:00
002d5c9c53 add scheme to metadata
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-19 23:25:22 +03:00
1d25e59860 Merge pull request 'move down path handler after specific handler' (#163) from path-handler-v3 into v3
Reviewed-on: #163
2023-05-19 23:04:16 +03:00
ce26e8bf63 move down path handler after specific handler
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-19 23:03:04 +03:00
8e09142b90 Merge pull request 'check subscribe errors' (#162) from subscribeerr into v3
Reviewed-on: #162
2023-05-13 16:09:47 +03:00
13bf2bbb1e check subscribe errors
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-13 16:09:21 +03:00
ba292901d7 fixup build
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-09 21:14:55 +03:00
6d1b6c7014 allow to expose some method via http.HandlerFunc
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-09 21:13:11 +03:00
1276f99159 export Server to allow to cast
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-09 21:12:47 +03:00
5 changed files with 404 additions and 45 deletions

View File

@@ -60,13 +60,286 @@ func (h *httpHandler) Options() server.HandlerOptions {
return h.opts return h.opts
} }
func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error) {
// check for http.HandlerFunc handlers if handler == nil {
if ph, _, err := h.pathHandlers.Search(r.Method, r.URL.Path); err == nil { return nil, fmt.Errorf("invalid handler specified: %v", handler)
ph.(http.HandlerFunc)(w, r)
return
} }
rtype := reflect.TypeOf(handler)
if rtype.NumIn() != 3 {
return nil, fmt.Errorf("invalid handler, NumIn != 3: %v", rtype.NumIn())
}
argType := rtype.In(1)
replyType := rtype.In(2)
// First arg need not be a pointer.
if !isExportedOrBuiltinType(argType) {
return nil, fmt.Errorf("invalid handler, argument type not exported: %v", argType)
}
if replyType.Kind() != reflect.Ptr {
return nil, fmt.Errorf("invalid handler, reply type not a pointer: %v", replyType)
}
// Reply type must be exported.
if !isExportedOrBuiltinType(replyType) {
return nil, fmt.Errorf("invalid handler, reply type not exported: %v", replyType)
}
if rtype.NumOut() != 1 {
return nil, fmt.Errorf("invalid handler, has wrong number of outs: %v", rtype.NumOut())
}
// The return type of the method must be error.
if returnType := rtype.Out(0); returnType != typeOfError {
return nil, fmt.Errorf("invalid handler, returns %v not error", returnType.String())
}
return func(w http.ResponseWriter, r *http.Request) {
ct := DefaultContentType
if htype := r.Header.Get(metadata.HeaderContentType); htype != "" {
ct = htype
}
ctx := context.WithValue(r.Context(), rspCodeKey{}, &rspCodeVal{})
ctx = context.WithValue(ctx, rspHeaderKey{}, &rspHeaderVal{})
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
md = metadata.New(len(r.Header) + 8)
}
for k, v := range r.Header {
md[k] = strings.Join(v, ", ")
}
md["RemoteAddr"] = r.RemoteAddr
md["Method"] = r.Method
md["URL"] = r.URL.String()
md["Proto"] = r.Proto
md["ContentLength"] = fmt.Sprintf("%d", r.ContentLength)
md["TransferEncoding"] = strings.Join(r.TransferEncoding, ",")
md["Host"] = r.Host
md["RequestURI"] = r.RequestURI
if r.TLS != nil {
md["TLS"] = "true"
md["TLS_ALPN"] = r.TLS.NegotiatedProtocol
md["TLS_ServerName"] = r.TLS.ServerName
}
ctx = metadata.NewIncomingContext(ctx, md)
path := r.URL.Path
if r.Body != nil {
defer r.Body.Close()
}
matches := make(map[string]interface{})
var match bool
var hldr *patHandler
var handler *httpHandler
for _, shdlr := range h.handlers {
hdlr := shdlr.(*httpHandler)
fh, mp, err := hdlr.handlers.Search(r.Method, path)
if err == nil {
match = true
for k, v := range mp {
matches[k] = v
}
hldr = fh.(*patHandler)
handler = hdlr
break
} else if err == rhttp.ErrMethodNotAllowed && !h.registerRPC {
w.WriteHeader(http.StatusMethodNotAllowed)
_, _ = w.Write([]byte("not matching route found"))
return
}
}
if !match && h.registerRPC {
microMethod, mok := md.Get(metadata.HeaderEndpoint)
if mok {
serviceMethod := strings.Split(microMethod, ".")
if len(serviceMethod) == 2 {
if shdlr, ok := h.handlers[serviceMethod[0]]; ok {
hdlr := shdlr.(*httpHandler)
fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod)
if err == nil {
match = true
for k, v := range mp {
matches[k] = v
}
hldr = fh.(*patHandler)
handler = hdlr
}
}
}
}
}
// get fields from url values
if len(r.URL.RawQuery) > 0 {
umd, cerr := rflutil.URLMap(r.URL.RawQuery)
if cerr != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(cerr.Error()))
return
}
for k, v := range umd {
matches[k] = v
}
}
cf, err := h.newCodec(ct)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(err.Error()))
return
}
var argv, replyv reflect.Value
// Decode the argument value.
argIsValue := false // if true, need to indirect before calling.
if hldr.mtype.ArgType.Kind() == reflect.Ptr {
argv = reflect.New(hldr.mtype.ArgType.Elem())
} else {
argv = reflect.New(hldr.mtype.ArgType)
argIsValue = true
}
if argIsValue {
argv = argv.Elem()
}
// reply value
replyv = reflect.New(hldr.mtype.ReplyType.Elem())
function := hldr.mtype.method.Func
var returnValues []reflect.Value
if r.Body != nil {
var buf []byte
buf, err = io.ReadAll(r.Body)
if err != nil && err != io.EOF {
h.errorHandler(ctx, handler, w, r, err, http.StatusInternalServerError)
return
}
if err = cf.Unmarshal(buf, argv.Interface()); err != nil {
h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest)
return
}
}
matches = rflutil.FlattenMap(matches)
if err = rflutil.Merge(argv.Interface(), matches, rflutil.SliceAppend(true), rflutil.Tags([]string{"protobuf", "json"})); err != nil {
h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest)
return
}
hr := &rpcRequest{
codec: cf,
service: handler.sopts.Name,
contentType: ct,
method: fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name),
endpoint: fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name),
payload: argv.Interface(),
header: md,
}
// define the handler func
fn := func(fctx context.Context, req server.Request, rsp interface{}) (err error) {
returnValues = function.Call([]reflect.Value{hldr.rcvr, hldr.mtype.prepareContext(fctx), argv, reflect.ValueOf(rsp)})
// The return value for the method is an error.
if rerr := returnValues[0].Interface(); rerr != nil {
err = rerr.(error)
}
md, ok := metadata.FromOutgoingContext(ctx)
if !ok {
md = metadata.New(0)
}
if nmd, ok := metadata.FromOutgoingContext(fctx); ok {
for k, v := range nmd {
md.Set(k, v)
}
}
metadata.SetOutgoingContext(ctx, md)
return err
}
// wrap the handler func
for i := len(handler.sopts.HdlrWrappers); i > 0; i-- {
fn = handler.sopts.HdlrWrappers[i-1](fn)
}
if ct == "application/x-www-form-urlencoded" {
cf, err = h.newCodec(DefaultContentType)
if err != nil {
h.errorHandler(ctx, handler, w, r, err, http.StatusInternalServerError)
return
}
ct = DefaultContentType
}
scode := int(200)
appErr := fn(ctx, hr, replyv.Interface())
w.Header().Set(metadata.HeaderContentType, ct)
if md, ok := metadata.FromOutgoingContext(ctx); ok {
for k, v := range md {
w.Header().Set(k, v)
}
}
if md := getRspHeader(ctx); md != nil {
for k, v := range md {
for _, vv := range v {
w.Header().Add(k, vv)
}
}
}
if nct := w.Header().Get(metadata.HeaderContentType); nct != ct {
if cf, err = h.newCodec(nct); err != nil {
h.errorHandler(ctx, nil, w, r, err, http.StatusBadRequest)
return
}
}
var buf []byte
if appErr != nil {
switch verr := appErr.(type) {
case *errors.Error:
scode = int(verr.Code)
buf, err = cf.Marshal(verr)
case *Error:
buf, err = cf.Marshal(verr.err)
default:
buf, err = cf.Marshal(appErr)
}
} else {
buf, err = cf.Marshal(replyv.Interface())
}
if err != nil && handler.sopts.Logger.V(logger.ErrorLevel) {
handler.sopts.Logger.Errorf(handler.sopts.Context, "handler err: %v", err)
return
}
if nscode := GetRspCode(ctx); nscode != 0 {
scode = nscode
}
w.WriteHeader(scode)
if _, cerr := w.Write(buf); cerr != nil {
handler.sopts.Logger.Errorf(ctx, "write failed: %v", cerr)
}
}, nil
}
func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ct := DefaultContentType ct := DefaultContentType
if htype := r.Header.Get(metadata.HeaderContentType); htype != "" { if htype := r.Header.Get(metadata.HeaderContentType); htype != "" {
ct = htype ct = htype
@@ -82,17 +355,22 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
md[k] = strings.Join(v, ", ") md[k] = strings.Join(v, ", ")
} }
md["RemoteAddr"] = r.RemoteAddr md["RemoteAddr"] = r.RemoteAddr
if r.TLS != nil {
md["Scheme"] = "https"
} else {
md["Scheme"] = "http"
}
md["Method"] = r.Method md["Method"] = r.Method
md["URL"] = r.URL.String() md["URL"] = r.URL.String()
md["Proto"] = r.Proto md["Proto"] = r.Proto
md["ContentLength"] = fmt.Sprintf("%d", r.ContentLength) md["ContentLength"] = fmt.Sprintf("%d", r.ContentLength)
md["TransferEncoding"] = strings.Join(r.TransferEncoding, ",") if len(r.TransferEncoding) > 0 {
md["TransferEncoding"] = strings.Join(r.TransferEncoding, ",")
}
md["Host"] = r.Host md["Host"] = r.Host
md["RequestURI"] = r.RequestURI md["RequestURI"] = r.RequestURI
ctx = metadata.NewIncomingContext(ctx, md) ctx = metadata.NewIncomingContext(ctx, md)
defer r.Body.Close()
path := r.URL.Path path := r.URL.Path
if !strings.HasPrefix(path, "/") { if !strings.HasPrefix(path, "/") {
h.errorHandler(ctx, nil, w, r, fmt.Errorf("path must starts with /"), http.StatusBadRequest) h.errorHandler(ctx, nil, w, r, fmt.Errorf("path must starts with /"), http.StatusBadRequest)
@@ -149,6 +427,11 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
} else if !match { } else if !match {
// check for http.HandlerFunc handlers
if ph, _, err := h.pathHandlers.Search(r.Method, r.URL.Path); err == nil {
ph.(http.HandlerFunc)(w, r)
return
}
h.errorHandler(ctx, nil, w, r, fmt.Errorf("not matching route found"), http.StatusNotFound) h.errorHandler(ctx, nil, w, r, fmt.Errorf("not matching route found"), http.StatusNotFound)
return return
} }
@@ -165,6 +448,10 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
if r.Body != nil {
defer r.Body.Close()
}
cf, err := h.newCodec(ct) cf, err := h.newCodec(ct)
if err != nil { if err != nil {
h.errorHandler(ctx, nil, w, r, err, http.StatusBadRequest) h.errorHandler(ctx, nil, w, r, err, http.StatusBadRequest)
@@ -192,21 +479,26 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
function := hldr.mtype.method.Func function := hldr.mtype.method.Func
var returnValues []reflect.Value var returnValues []reflect.Value
buf, err := io.ReadAll(r.Body) if r.Body != nil {
if err != nil && err != io.EOF { var buf []byte
h.errorHandler(ctx, handler, w, r, err, http.StatusInternalServerError) buf, err = io.ReadAll(r.Body)
return if err != nil && err != io.EOF {
h.errorHandler(ctx, handler, w, r, err, http.StatusInternalServerError)
return
}
if err = cf.Unmarshal(buf, argv.Interface()); err != nil {
h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest)
return
}
} }
if err = cf.Unmarshal(buf, argv.Interface()); err != nil { if len(matches) > 0 {
h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest) matches = rflutil.FlattenMap(matches)
return if err = rflutil.Merge(argv.Interface(), matches, rflutil.SliceAppend(true), rflutil.Tags([]string{"protobuf", "json"})); err != nil {
} h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest)
return
matches = rflutil.FlattenMap(matches) }
if err = rflutil.Merge(argv.Interface(), matches, rflutil.SliceAppend(true), rflutil.Tags([]string{"protobuf", "json"})); err != nil {
h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest)
return
} }
hr := &rpcRequest{ hr := &rpcRequest{
@@ -279,6 +571,7 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
var buf []byte
if appErr != nil { if appErr != nil {
switch verr := appErr.(type) { switch verr := appErr.(type) {
case *errors.Error: case *errors.Error:

View File

@@ -0,0 +1,55 @@
package swagger
import (
"io/fs"
"net/http"
yamlcodec "go.unistack.org/micro-codec-yaml/v3"
rutil "go.unistack.org/micro/v3/util/reflect"
)
// Handler append to generated swagger data from dst map[string]interface{}
var Handler = func(dst map[string]interface{}, fsys fs.FS) http.HandlerFunc {
c := yamlcodec.NewCodec()
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusNotFound)
return
}
path := r.URL.Path
if len(path) > 1 && path[0] == '/' {
path = path[1:]
}
buf, err := fs.ReadFile(fsys, path)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}
var src interface{}
if err = c.Unmarshal(buf, src); err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}
if err = rutil.Merge(src, dst); err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}
if buf, err = c.Marshal(src); err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write(buf)
}
}

53
http.go
View File

@@ -23,9 +23,9 @@ import (
"golang.org/x/net/netutil" "golang.org/x/net/netutil"
) )
var _ server.Server = &httpServer{} var _ server.Server = (*Server)(nil)
type httpServer struct { type Server struct {
hd server.Handler hd server.Handler
rsvc *register.Service rsvc *register.Service
handlers map[string]server.Handler handlers map[string]server.Handler
@@ -40,7 +40,7 @@ type httpServer struct {
init bool init bool
} }
func (h *httpServer) newCodec(ct string) (codec.Codec, error) { func (h *Server) newCodec(ct string) (codec.Codec, error) {
if idx := strings.IndexRune(ct, ';'); idx >= 0 { if idx := strings.IndexRune(ct, ';'); idx >= 0 {
ct = ct[:idx] ct = ct[:idx]
} }
@@ -53,14 +53,14 @@ func (h *httpServer) newCodec(ct string) (codec.Codec, error) {
return nil, codec.ErrUnknownContentType return nil, codec.ErrUnknownContentType
} }
func (h *httpServer) Options() server.Options { func (h *Server) Options() server.Options {
h.Lock() h.Lock()
opts := h.opts opts := h.opts
h.Unlock() h.Unlock()
return opts return opts
} }
func (h *httpServer) Init(opts ...server.Option) error { func (h *Server) Init(opts ...server.Option) error {
if len(opts) == 0 && h.init { if len(opts) == 0 && h.init {
return nil return nil
} }
@@ -130,7 +130,7 @@ func (h *httpServer) Init(opts ...server.Option) error {
return nil return nil
} }
func (h *httpServer) Handle(handler server.Handler) error { func (h *Server) Handle(handler server.Handler) error {
// passed unknown handler // passed unknown handler
hdlr, ok := handler.(*httpHandler) hdlr, ok := handler.(*httpHandler)
if !ok { if !ok {
@@ -159,7 +159,7 @@ func (h *httpServer) Handle(handler server.Handler) error {
return nil return nil
} }
func (h *httpServer) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler { func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler {
options := server.NewHandlerOptions(opts...) options := server.NewHandlerOptions(opts...)
eps := make([]*register.Endpoint, 0, len(options.Metadata)) eps := make([]*register.Endpoint, 0, len(options.Metadata))
@@ -288,11 +288,11 @@ func (h *httpServer) NewHandler(handler interface{}, opts ...server.HandlerOptio
return hdlr return hdlr
} }
func (h *httpServer) NewSubscriber(topic string, handler interface{}, opts ...server.SubscriberOption) server.Subscriber { func (h *Server) NewSubscriber(topic string, handler interface{}, opts ...server.SubscriberOption) server.Subscriber {
return newSubscriber(topic, handler, opts...) return newSubscriber(topic, handler, opts...)
} }
func (h *httpServer) Subscribe(sb server.Subscriber) error { func (h *Server) Subscribe(sb server.Subscriber) error {
sub, ok := sb.(*httpSubscriber) sub, ok := sb.(*httpSubscriber)
if !ok { if !ok {
return fmt.Errorf("invalid subscriber: expected *httpSubscriber") return fmt.Errorf("invalid subscriber: expected *httpSubscriber")
@@ -317,7 +317,7 @@ func (h *httpServer) Subscribe(sb server.Subscriber) error {
return nil return nil
} }
func (h *httpServer) Register() error { func (h *Server) Register() error {
var eps []*register.Endpoint var eps []*register.Endpoint
h.RLock() h.RLock()
for _, hdlr := range h.handlers { for _, hdlr := range h.handlers {
@@ -378,6 +378,17 @@ func (h *httpServer) Register() error {
} }
h.Lock() h.Lock()
h.registered = true
h.rsvc = service
h.Unlock()
return nil
}
func (h *Server) subscribe() error {
config := h.opts
for sb := range h.subscribers { for sb := range h.subscribers {
handler := h.createSubHandler(sb, config) handler := h.createSubHandler(sb, config)
var opts []broker.SubscribeOption var opts []broker.SubscribeOption
@@ -401,14 +412,10 @@ func (h *httpServer) Register() error {
h.subscribers[sb] = []broker.Subscriber{sub} h.subscribers[sb] = []broker.Subscriber{sub}
} }
h.registered = true
h.rsvc = service
h.Unlock()
return nil return nil
} }
func (h *httpServer) Deregister() error { func (h *Server) Deregister() error {
h.RLock() h.RLock()
config := h.opts config := h.opts
h.RUnlock() h.RUnlock()
@@ -456,7 +463,7 @@ func (h *httpServer) Deregister() error {
return nil return nil
} }
func (h *httpServer) Start() error { func (h *Server) Start() error {
h.RLock() h.RLock()
config := h.opts config := h.opts
h.RUnlock() h.RUnlock()
@@ -539,6 +546,10 @@ func (h *httpServer) Start() error {
} }
} }
if err := h.subscribe(); err != nil {
return err
}
fn := handler fn := handler
if h.opts.Context != nil { if h.opts.Context != nil {
@@ -636,27 +647,27 @@ func (h *httpServer) Start() error {
return nil return nil
} }
func (h *httpServer) Stop() error { func (h *Server) Stop() error {
ch := make(chan error) ch := make(chan error)
h.exit <- ch h.exit <- ch
return <-ch return <-ch
} }
func (h *httpServer) String() string { func (h *Server) String() string {
return "http" return "http"
} }
func (h *httpServer) Name() string { func (h *Server) Name() string {
return h.opts.Name return h.opts.Name
} }
func NewServer(opts ...server.Option) *httpServer { func NewServer(opts ...server.Option) *Server {
options := server.NewOptions(opts...) options := server.NewOptions(opts...)
eh := DefaultErrorHandler eh := DefaultErrorHandler
if v, ok := options.Context.Value(errorHandlerKey{}).(errorHandler); ok && v != nil { if v, ok := options.Context.Value(errorHandlerKey{}).(errorHandler); ok && v != nil {
eh = v eh = v
} }
return &httpServer{ return &Server{
opts: options, opts: options,
exit: make(chan chan error), exit: make(chan chan error),
subscribers: make(map[*httpSubscriber][]broker.Subscriber), subscribers: make(map[*httpSubscriber][]broker.Subscriber),

View File

@@ -85,8 +85,8 @@ func Middleware(mw ...func(http.Handler) http.Handler) server.Option {
type serverKey struct{} type serverKey struct{}
// Server provide ability to pass *http.Server // HTTPServer provide ability to pass *http.Server
func Server(hs *http.Server) server.Option { func HTTPServer(hs *http.Server) server.Option {
return server.SetOption(serverKey{}, hs) return server.SetOption(serverKey{}, hs)
} }

View File

@@ -101,7 +101,7 @@ func newSubscriber(topic string, sub interface{}, opts ...server.SubscriberOptio
} }
} }
func (s *httpServer) createSubHandler(sb *httpSubscriber, opts server.Options) broker.Handler { func (s *Server) createSubHandler(sb *httpSubscriber, opts server.Options) broker.Handler {
return func(p broker.Event) error { return func(p broker.Event) error {
msg := p.Message() msg := p.Message()
ct := msg.Header["Content-Type"] ct := msg.Header["Content-Type"]