fix:http rehister url lack / (#1464)

* fix: set strictSlash true
pull/1465/head
seasrain 3 years ago committed by GitHub
parent 6e6526efd9
commit 798adbff5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      transport/http/server.go

@ -105,6 +105,15 @@ func TLSConfig(c *tls.Config) ServerOption {
}
}
// StrictSlash is with mux's StrictSlash
// If true, when the path pattern is "/path/", accessing "/path" will
// redirect to the former and vice versa.
func StrictSlash(strictSlash bool) ServerOption {
return func(o *Server) {
o.strictSlash = strictSlash
}
}
// Server is an HTTP server wrapper.
type Server struct {
*http.Server
@ -121,6 +130,7 @@ type Server struct {
dec DecodeRequestFunc
enc EncodeResponseFunc
ene EncodeErrorFunc
strictSlash bool
router *mux.Router
log *log.Helper
}
@ -134,12 +144,13 @@ func NewServer(opts ...ServerOption) *Server {
dec: DefaultRequestDecoder,
enc: DefaultResponseEncoder,
ene: DefaultErrorEncoder,
strictSlash: true,
log: log.NewHelper(log.DefaultLogger),
}
for _, o := range opts {
o(srv)
}
srv.router = mux.NewRouter()
srv.router = mux.NewRouter().StrictSlash(srv.strictSlash)
srv.router.Use(srv.filter())
srv.Server = &http.Server{
Handler: FilterChain(srv.filters...)(srv.router),

Loading…
Cancel
Save