fix handler context metadata passing

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-03-01 13:02:35 +03:00
parent 45670661d0
commit e88f524042

View File

@ -67,7 +67,7 @@ func (h *httpHandler) Options() server.HandlerOptions {
} }
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := metadata.NewContext(r.Context(), nil)
defer r.Body.Close() defer r.Body.Close()
@ -187,17 +187,21 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var scode int var scode int
// define the handler func // define the handler func
fn := func(ctx context.Context, req server.Request, rsp interface{}) (err error) { fn := func(fctx context.Context, req server.Request, rsp interface{}) (err error) {
ctx = context.WithValue(ctx, rspCodeKey{}, &rspCodeVal{}) fctx = context.WithValue(fctx, rspCodeKey{}, &rspCodeVal{})
ctx = metadata.NewIncomingContext(ctx, md) fctx = metadata.NewIncomingContext(fctx, md)
returnValues = function.Call([]reflect.Value{hldr.rcvr, hldr.mtype.prepareContext(ctx), reflect.ValueOf(argv.Interface()), reflect.ValueOf(rsp)}) returnValues = function.Call([]reflect.Value{hldr.rcvr, hldr.mtype.prepareContext(fctx), reflect.ValueOf(argv.Interface()), reflect.ValueOf(rsp)})
scode = GetRspCode(ctx) scode = GetRspCode(fctx)
// The return value for the method is an error. // The return value for the method is an error.
if rerr := returnValues[0].Interface(); rerr != nil { if rerr := returnValues[0].Interface(); rerr != nil {
err = rerr.(error) err = rerr.(error)
} }
if md, ok := metadata.FromOutgoingContext(fctx); ok {
metadata.SetOutgoingContext(ctx, md)
}
return err return err
} }