Skip to content

Commit

Permalink
api gateway handing http request adds Content-Type application/x-www-…
Browse files Browse the repository at this point in the history
…form-urlencoded, and extract endpoints from path if no endpoint matched (#2592)

Co-authored-by: l <l@x>
  • Loading branch information
leoujz and l authored Nov 9, 2022
1 parent a17eaf6 commit 0a91ba7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/handler/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 12 additions & 1 deletion api/router/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0a91ba7

Please sign in to comment.