mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
api minor improvements (#1526)
* api/handler/rpc: unblock all http methods and set Host meta * api/router/static: add debug log Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
ec80ceb8c2
commit
0a2363b49b
@ -100,8 +100,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// only allow post when we have the router
|
if h.opts.Router == nil && r.Method != "GET" {
|
||||||
if r.Method != "GET" && (h.opts.Router != nil && r.Method != "POST") {
|
|
||||||
writeError(w, r, errors.MethodNotAllowed("go.micro.api", "method not allowed"))
|
writeError(w, r, errors.MethodNotAllowed("go.micro.api", "method not allowed"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -123,7 +122,8 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
md = make(metadata.Metadata)
|
md = make(metadata.Metadata)
|
||||||
}
|
}
|
||||||
|
// fill contex with http headers
|
||||||
|
md["Host"] = r.Host
|
||||||
// merge context with overwrite
|
// merge context with overwrite
|
||||||
cx = metadata.MergeContext(cx, md, true)
|
cx = metadata.MergeContext(cx, md, true)
|
||||||
|
|
||||||
|
@ -264,7 +264,9 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
|
|||||||
for _, pathreg := range ep.pathregs {
|
for _, pathreg := range ep.pathregs {
|
||||||
matches, err := pathreg.Match(path, "")
|
matches, err := pathreg.Match(path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: log error
|
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||||
|
logger.Debugf("api path not match %s != %v", path, pathreg)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pMatch = true
|
pMatch = true
|
||||||
@ -290,7 +292,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no match
|
// no match
|
||||||
return nil, fmt.Errorf("endpoint not found for %v", req)
|
return nil, fmt.Errorf("endpoint not found for %v", req.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *staticRouter) Route(req *http.Request) (*api.Service, error) {
|
func (r *staticRouter) Route(req *http.Request) (*api.Service, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user