fix api metadata extract from context (#1452)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
d6bef84de0
commit
18061723bb
@ -118,6 +118,17 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// create context
|
// create context
|
||||||
cx := ctx.FromRequest(r)
|
cx := ctx.FromRequest(r)
|
||||||
|
// get context from http handler wrappers
|
||||||
|
md, ok := r.Context().Value(metadata.MetadataKey{}).(metadata.Metadata)
|
||||||
|
if !ok {
|
||||||
|
md = make(metadata.Metadata)
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge context with overwrite
|
||||||
|
cx = metadata.MergeContext(cx, md, true)
|
||||||
|
|
||||||
|
// set merged context to request
|
||||||
|
*r = *r.WithContext(cx)
|
||||||
|
|
||||||
// if stream we currently only support json
|
// if stream we currently only support json
|
||||||
if isStream(r, service) {
|
if isStream(r, service) {
|
||||||
@ -287,6 +298,7 @@ func requestPayload(r *http.Request) ([]byte, error) {
|
|||||||
// allocate maximum
|
// allocate maximum
|
||||||
matches := make(map[string]string, len(md))
|
matches := make(map[string]string, len(md))
|
||||||
for k, v := range md {
|
for k, v := range md {
|
||||||
|
// filter own keys
|
||||||
if strings.HasPrefix(k, "x-api-field-") {
|
if strings.HasPrefix(k, "x-api-field-") {
|
||||||
matches[strings.TrimPrefix(k, "x-api-field-")] = v
|
matches[strings.TrimPrefix(k, "x-api-field-")] = v
|
||||||
delete(md, k)
|
delete(md, k)
|
||||||
@ -294,8 +306,8 @@ func requestPayload(r *http.Request) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// restore context without fields
|
// restore context without fields
|
||||||
ctx = metadata.NewContext(ctx, md)
|
*r = *r.WithContext(metadata.NewContext(ctx, md))
|
||||||
*r = *r.WithContext(ctx)
|
|
||||||
req := make(map[string]interface{}, len(md))
|
req := make(map[string]interface{}, len(md))
|
||||||
for k, v := range matches {
|
for k, v := range matches {
|
||||||
ps := strings.Split(k, ".")
|
ps := strings.Split(k, ".")
|
||||||
|
@ -255,7 +255,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
|
|||||||
}
|
}
|
||||||
pMatch = true
|
pMatch = true
|
||||||
ctx := req.Context()
|
ctx := req.Context()
|
||||||
md, ok := metadata.FromContext(ctx)
|
md, ok := ctx.Value(metadata.MetadataKey{}).(metadata.Metadata)
|
||||||
if !ok {
|
if !ok {
|
||||||
md = make(metadata.Metadata)
|
md = make(metadata.Metadata)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user