MCPcopy
hub / github.com/gin-gonic/gin / redirectTrailingSlash

Function redirectTrailingSlash

gin.go:781–795  ·  view source on GitHub ↗
(c *Context)

Source from the content-addressed store, hash-verified

779}
780
781func redirectTrailingSlash(c *Context) {
782 req := c.Request
783 p := req.URL.Path
784 if prefix := path.Clean(c.Request.Header.Get("X-Forwarded-Prefix")); prefix != "." {
785 prefix = sanitizePathChars(prefix)
786 prefix = removeRepeatedChar(prefix, '/')
787
788 p = prefix + "/" + req.URL.Path
789 }
790 req.URL.Path = p + "/"
791 if length := len(p); length > 1 && p[length-1] == '/' {
792 req.URL.Path = p[:length-1]
793 }
794 redirectRequest(c)
795}
796
797// sanitizePathChars removes unsafe characters from path strings,
798// keeping only ASCII letters, ASCII numbers, forward slashes, and hyphens.

Callers 1

handleHTTPRequestMethod · 0.85

Calls 4

sanitizePathCharsFunction · 0.85
removeRepeatedCharFunction · 0.85
redirectRequestFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected