Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [transport client] <考虑到缓存中间件命中缓存的情况,增加一步在闭包外给reply赋值的操作> #3411

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
16 changes: 14 additions & 2 deletions transport/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"reflect"
"time"

"github.com/go-kratos/kratos/v2/encoding"
Expand Down Expand Up @@ -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.
Expand Down