The regular match contains a slash, but an extra slash is spliced below.
|
var re = regexp.MustCompile(`^(.*/)([^?].*)?[?|.]*$`) |
|
|
|
return func(c echo.Context) error { |
|
if c.Request().Method != http.MethodGet { |
|
return echo.NewHTTPError(http.StatusMethodNotAllowed, http.StatusText(http.StatusMethodNotAllowed)) |
|
} |
|
|
|
matches := re.FindStringSubmatch(c.Request().RequestURI) |
|
path := matches[2] |
|
|
|
switch filepath.Ext(path) { |
|
case ".html": |
|
c.Response().Header().Set("Content-Type", "text/html; charset=utf-8") |
|
case ".css": |
|
c.Response().Header().Set("Content-Type", "text/css; charset=utf-8") |
|
case ".js": |
|
c.Response().Header().Set("Content-Type", "application/javascript") |
|
case ".json": |
|
c.Response().Header().Set("Content-Type", "application/json; charset=utf-8") |
|
case ".yaml": |
|
c.Response().Header().Set("Content-Type", "text/plain; charset=utf-8") |
|
case ".png": |
|
c.Response().Header().Set("Content-Type", "image/png") |
|
} |
|
|
|
response := c.Response() |
|
// This check fixes an error introduced here: https://github.com/labstack/echo/blob/8da8e161380fd926d4341721f0328f1e94d6d0a2/response.go#L86-L88 |
|
if _, ok := response.Writer.(http.Flusher); ok { |
|
defer response.Flush() |
|
} |
|
|
|
switch path { |
|
case "": |
|
_ = c.Redirect(http.StatusMovedPermanently, matches[1]+"/"+"index.html") |
So if you access the path /swagger/, you will get /swagger//index.html
The regular match contains a slash, but an extra slash is spliced below.
echo-swagger/swagger.go
Lines 131 to 164 in 5602047
So if you access the path
/swagger/, you will get/swagger//index.html