diff --git a/transport/http/client.go b/transport/http/client.go index 1d74542d522..0b70be93065 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "reflect" "time" "github.com/go-kratos/kratos/v2/encoding" @@ -274,8 +275,19 @@ func (client *Client) invoke(ctx context.Context, req *http.Request, args interf if len(client.opts.middleware) > 0 { h = middleware.Chain(client.opts.middleware...)(h) } - _, err := h(ctx, args) - return err + ret, err := h(ctx, args) + if err != nil { + return err + } + retValue := reflect.ValueOf(ret) + replyValue := reflect.ValueOf(reply) + if replyValue.Kind() == reflect.Ptr && !replyValue.IsNil() && retValue.Type() == replyValue.Elem().Type() { + replyValue.Elem().Set(retValue.Elem()) + } else { + reply = ret + } + + return nil } // Do send an HTTP request and decodes the body of response into target.