mirror of
				https://github.com/traefik/traefik.git
				synced 2025-11-04 02:11:15 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			638 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			638 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package middlewares
 | 
						|
 | 
						|
import (
 | 
						|
	"net/http"
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
// StripPrefix is a middleware used to strip prefix from an URL request
 | 
						|
type StripPrefix struct {
 | 
						|
	Handler  http.Handler
 | 
						|
	Prefixes []string
 | 
						|
}
 | 
						|
 | 
						|
func (s *StripPrefix) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 | 
						|
	for _, prefix := range s.Prefixes {
 | 
						|
		if p := strings.TrimPrefix(r.URL.Path, strings.TrimSpace(prefix)); len(p) < len(r.URL.Path) {
 | 
						|
			r.URL.Path = p
 | 
						|
			r.RequestURI = r.URL.RequestURI()
 | 
						|
			s.Handler.ServeHTTP(w, r)
 | 
						|
			return
 | 
						|
		}
 | 
						|
	}
 | 
						|
	http.NotFound(w, r)
 | 
						|
}
 | 
						|
 | 
						|
// SetHandler sets handler
 | 
						|
func (s *StripPrefix) SetHandler(Handler http.Handler) {
 | 
						|
	s.Handler = Handler
 | 
						|
}
 |