MCPcopy
hub / github.com/labstack/echo / ToMiddleware

Method ToMiddleware

middleware/redirect.go:119–145  ·  view source on GitHub ↗

ToMiddleware converts RedirectConfig to middleware or returns an error for invalid configuration

()

Source from the content-addressed store, hash-verified

117
118// ToMiddleware converts RedirectConfig to middleware or returns an error for invalid configuration
119func (config RedirectConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
120 if config.Skipper == nil {
121 config.Skipper = DefaultSkipper
122 }
123 if config.Code == 0 {
124 config.Code = http.StatusMovedPermanently
125 }
126 if config.redirect == nil {
127 return nil, errors.New("redirectConfig is missing redirect function")
128 }
129
130 return func(next echo.HandlerFunc) echo.HandlerFunc {
131 return func(c *echo.Context) error {
132 if config.Skipper(c) {
133 return next(c)
134 }
135
136 req, scheme := c.Request(), c.Scheme()
137 host := req.Host
138 if ok, url := config.redirect(scheme, host, req.RequestURI); ok {
139 return c.Redirect(config.Code, url)
140 }
141
142 return next(c)
143 }
144 }, nil
145}
146
147var redirectHTTPS = func(scheme, host, uri string) (bool, string) {
148 if scheme != "https" {

Callers

nothing calls this directly

Calls 3

RequestMethod · 0.80
SchemeMethod · 0.80
RedirectMethod · 0.80

Tested by

no test coverage detected