Documentation ¶
Overview ¶
Package rewrite is middleware for rewriting requests internally to a different path.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComplexRule ¶
type ComplexRule struct { // Path base. Request to this path and subpaths will be rewritten Base string // Path to rewrite to To string // If set, neither performs rewrite nor proceeds // with request. Only returns code. Status int // Extensions to filter by Exts []string // Request matcher httpserver.RequestMatcher *regexp.Regexp }
ComplexRule is a rewrite rule based on a regular expression
func NewComplexRule ¶
func NewComplexRule(base, pattern, to string, status int, ext []string, matcher httpserver.RequestMatcher) (*ComplexRule, error)
NewComplexRule creates a new RegexpRule. It returns an error if regexp pattern (pattern) or extensions (ext) are invalid.
func (*ComplexRule) BasePath ¶
func (r *ComplexRule) BasePath() string
BasePath satisfies httpserver.Config
func (*ComplexRule) Match ¶
func (r *ComplexRule) Match(req *http.Request) bool
Match satisfies httpserver.Config.
Though ComplexRule embeds a RequestMatcher, additional checks are needed which requires a custom implementation.
func (*ComplexRule) Rewrite ¶
func (r *ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Result)
Rewrite rewrites the internal location of the current request.
type Result ¶
type Result int
Result is the result of a rewrite
func To ¶
func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Replacer) Result
To attempts rewrite. It attempts to rewrite to first valid path or the last path if none of the paths are valid.
type Rewrite ¶
type Rewrite struct { Next httpserver.Handler FileSys http.FileSystem Rules []httpserver.HandlerConfig }
Rewrite is middleware to rewrite request locations internally before being handled.
type Rule ¶
type Rule interface { httpserver.HandlerConfig // Rewrite rewrites the internal location of the current request. Rewrite(http.FileSystem, *http.Request) Result }
Rule describes an internal location rewrite rule.
type SimpleRule ¶
type SimpleRule struct {
From, To string
}
SimpleRule is a simple rewrite rule.
func NewSimpleRule ¶
func NewSimpleRule(from, to string) SimpleRule
NewSimpleRule creates a new Simple Rule
func (SimpleRule) BasePath ¶
func (s SimpleRule) BasePath() string
BasePath satisfies httpserver.Config
func (SimpleRule) Match ¶
func (s SimpleRule) Match(r *http.Request) bool
Match satisfies httpserver.Config
func (SimpleRule) Rewrite ¶
func (s SimpleRule) Rewrite(fs http.FileSystem, r *http.Request) Result
Rewrite rewrites the internal location of the current request.