fixup
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
a9bbe17047
commit
b2949459e1
20
util.go
20
util.go
@ -15,23 +15,30 @@ func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
for idx := 0; idx < len(options.headers)/2; idx += 2 {
|
||||
k := http.CanonicalHeaderKey(options.headers[idx])
|
||||
v, ok := md[k]
|
||||
k := options.headers[idx]
|
||||
v, ok := md.Get(k)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if err = rutil.SetFieldByPath(req, v, k); err != nil {
|
||||
|
||||
if len(v) == 1 {
|
||||
err = rutil.SetFieldByPath(req, v[0], k)
|
||||
} else {
|
||||
err = rutil.SetFieldByPath(req, v, k)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
cookieVals, _ := md["Cookie"]
|
||||
cookieVals, _ := md.Get("Cookie")
|
||||
for i := range cookieVals {
|
||||
cookies := strings.Split(cookieVals[i], ";")
|
||||
cmd := make(map[string]string, len(cookies))
|
||||
@ -45,10 +52,13 @@ func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption
|
||||
for idx := 0; idx < len(options.cookies)/2; idx += 2 {
|
||||
k := http.CanonicalHeaderKey(options.cookies[idx])
|
||||
v, ok := cmd[k]
|
||||
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if err = rutil.SetFieldByPath(req, v, k); err != nil {
|
||||
|
||||
err = rutil.SetFieldByPath(req, v, k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user