assert trailing slash for handler prefixes
This commit is contained in:
parent
89f016ed9d
commit
adfedc9239
@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
@ -60,6 +61,13 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
|
|||||||
// Inject extra handlers if given
|
// Inject extra handlers if given
|
||||||
// Used for grpc-gateway runtime.ServeMux handlers
|
// Used for grpc-gateway runtime.ServeMux handlers
|
||||||
for _, h := range opts.Handlers {
|
for _, h := range opts.Handlers {
|
||||||
|
// prefix must end in / to route sub-paths
|
||||||
|
if !strings.HasSuffix(h.Prefix, "/") {
|
||||||
|
h.Prefix = h.Prefix + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
// if enabled, the path prefix is stripped before
|
||||||
|
// requests are sent to the handler
|
||||||
if h.StripPrefix {
|
if h.StripPrefix {
|
||||||
h.Handler = http.StripPrefix(h.Prefix, h.Handler)
|
h.Handler = http.StripPrefix(h.Prefix, h.Handler)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user