Added ReplacePathRegex middleware
This commit is contained in:
parent
e8633d17e8
commit
5042c5bf40
5 changed files with 138 additions and 0 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -81,6 +82,7 @@ type serverRoute struct {
|
|||
stripPrefixesRegex []string
|
||||
addPrefix string
|
||||
replacePath string
|
||||
replacePathRegex string
|
||||
}
|
||||
|
||||
// NewServer returns an initialized Server.
|
||||
|
@ -1065,6 +1067,15 @@ func (server *Server) wireFrontendBackend(serverRoute *serverRoute, handler http
|
|||
}
|
||||
}
|
||||
|
||||
if len(serverRoute.replacePathRegex) > 0 {
|
||||
sp := strings.Split(serverRoute.replacePathRegex, " ")
|
||||
if len(sp) == 2 {
|
||||
handler = middlewares.NewReplacePathRegexHandler(sp[0], sp[1], handler)
|
||||
} else {
|
||||
log.Warnf("Invalid syntax for ReplacePathRegex: %s. Separate the regular expression and the replacement by a space.", serverRoute.replacePathRegex)
|
||||
}
|
||||
}
|
||||
|
||||
// add prefix - This needs to always be right before ReplacePath on the chain (second in order in this function)
|
||||
// -- Adding Path Prefix should happen after all *Strip Matcher+Modifiers ran, but before Replace (in case it's configured)
|
||||
if len(serverRoute.addPrefix) > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue