1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-10-30 23:27:41 +02:00

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 <l@x>
This commit is contained in:
leoujz
2022-11-09 11:28:39 +08:00
committed by GitHub
parent a17eaf64da
commit 0a91ba7b5d
2 changed files with 13 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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,