From 0a91ba7b5d7319ae71e551c21fe5134604490835 Mon Sep 17 00:00:00 2001 From: leoujz Date: Wed, 9 Nov 2022 11:28:39 +0800 Subject: [PATCH] api gateway handing http request adds Content-Type application/x-www-form-urlencoded, and extract endpoints from path if no endpoint matched (#2592) Co-authored-by: l --- api/handler/rpc/rpc.go | 2 +- api/router/registry/registry.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index ac103f4d50..9785361c4d 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -315,7 +315,7 @@ func requestPayload(r *http.Request) ([]byte, error) { } return raw.Marshal() - case strings.Contains(myCt, "application/www-x-form-urlencoded"): + case strings.Contains(myCt, "application/www-x-form-urlencoded"), strings.Contains(myCt, "application/x-www-form-urlencoded"): if err := r.ParseForm(); err != nil { return nil, err } diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index 522b40e0ff..35edf26279 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -452,11 +452,22 @@ func (r *registryRouter) Route(req *http.Request) (*router.Route, error) { handler = "rpc" } + // extract endpoint from Path, case-sensitive + // just test it in this case, maybe should put the code somewhere else + ep_name := rsp.Method + comps := strings.Split(rsp.Path, "/") + switch len(comps) { + case 3: + ep_name = comps[1] + "." + comps[2] + case 4: + ep_name = comps[2] + "." + comps[3] + } + // construct api service return &router.Route{ Service: name, Endpoint: &router.Endpoint{ - Name: rsp.Method, + Name: ep_name, Handler: handler, }, Versions: services,