fix rsp code for wrappers
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
b18465083b
commit
ba283695dd
24
handler.go
24
handler.go
@ -205,20 +205,25 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
header: md,
|
header: md,
|
||||||
}
|
}
|
||||||
|
|
||||||
var scode int
|
|
||||||
// define the handler func
|
// define the handler func
|
||||||
fn := func(fctx context.Context, req server.Request, rsp interface{}) (err error) {
|
fn := func(fctx context.Context, req server.Request, rsp interface{}) (err error) {
|
||||||
returnValues = function.Call([]reflect.Value{hldr.rcvr, hldr.mtype.prepareContext(fctx), 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(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 {
|
md, ok := metadata.FromOutgoingContext(ctx)
|
||||||
metadata.SetOutgoingContext(ctx, md)
|
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
|
return err
|
||||||
}
|
}
|
||||||
@ -237,6 +242,7 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
ct = DefaultContentType
|
ct = DefaultContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scode := int(200)
|
||||||
if appErr := fn(ctx, hr, replyv.Interface()); appErr != nil {
|
if appErr := fn(ctx, hr, replyv.Interface()); appErr != nil {
|
||||||
switch verr := appErr.(type) {
|
switch verr := appErr.(type) {
|
||||||
case *errors.Error:
|
case *errors.Error:
|
||||||
@ -262,12 +268,12 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("content-Type", ct)
|
w.Header().Set("content-Type", ct)
|
||||||
if scode != 0 {
|
|
||||||
w.WriteHeader(scode)
|
if nscode := GetRspCode(ctx); nscode != 0 {
|
||||||
} else {
|
scode = nscode
|
||||||
// handler.sopts.Logger.Warn(handler.sopts.Context, "response code not set in handler via SetRspCode(ctx, http.StatusXXX)")
|
|
||||||
w.WriteHeader(200)
|
|
||||||
}
|
}
|
||||||
|
w.WriteHeader(scode)
|
||||||
|
|
||||||
if _, cerr := w.Write(b); cerr != nil {
|
if _, cerr := w.Write(b); cerr != nil {
|
||||||
logger.DefaultLogger.Errorf(ctx, "write failed: %v", cerr)
|
logger.DefaultLogger.Errorf(ctx, "write failed: %v", cerr)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user