Fix web registry compatability bugs

This commit is contained in:
Ben Toogood 2020-04-03 09:18:30 +01:00
parent 8b35c264eb
commit fdcb013f24
3 changed files with 17 additions and 3 deletions

View File

@ -2,9 +2,15 @@
package resolver
import (
"errors"
"net/http"
)
var (
ErrNotFound = errors.New("not found")
ErrInvalidPath = errors.New("invalid path")
)
// Resolver resolves requests to endpoints
type Resolver interface {
Resolve(r *http.Request) (*Endpoint, error)

View File

@ -325,7 +325,7 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
}
// no match
return nil, errors.New("not found")
return nil, registry.ErrNotFound
}
func (r *registryRouter) Route(req *http.Request) (*api.Service, error) {

View File

@ -53,11 +53,19 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Determine the name of the service being requested
endpoint, err := h.resolver.Resolve(req)
if err != nil {
if err == resolver.ErrInvalidPath || err == resolver.ErrNotFound {
// a file not served by the resolver has been requested (e.g. favicon.ico)
endpoint = &resolver.Endpoint{Path: req.URL.Path}
} else if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
resName := h.namespace + "." + endpoint.Name
// construct the resource name, e.g. home => go.micro.web.home
resName := h.namespace
if len(endpoint.Name) > 0 {
resName = resName + "." + endpoint.Name
}
// Perform the verification check to see if the account has access to
// the resource they're requesting