summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers.go
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2019-09-17 15:16:17 -0600
committerGitHub <noreply@github.com>2019-09-17 15:16:17 -0600
commit484cee1ac12ee590128d85da22b6b9df2efe02d4 (patch)
treeddb5f20da081f8f3994d0dbe6fc7988d11a9620f /modules/caddyhttp/matchers.go
parentd030bfdae065c8776e8ac14c0a28f725ec05145c (diff)
fastcgi: Implement / redirect for index.php with php_fastcgi directive (#2754)
* fastcgi: Implement / redirect for index.php with php_fastcgi directive See #2752 and https://caddy.community/t/v2-redirect-path-to-path-index-php-with-assets/6196?u=matt * caddyhttp: MatchNegate implements json.Marshaler * fastcgi: Add /index.php element to try_files matcher * fastcgi: Make /index.php redirect permanent
Diffstat (limited to 'modules/caddyhttp/matchers.go')
-rw-r--r--modules/caddyhttp/matchers.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 94d051e..9cf52dc 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -66,9 +66,9 @@ type (
// MatchNegate matches requests by negating its matchers' results.
MatchNegate struct {
- matchersRaw map[string]json.RawMessage
+ MatchersRaw map[string]json.RawMessage `json:"-"`
- matchers MatcherSet
+ Matchers MatcherSet `json:"-"`
}
// MatchStarlarkExpr matches requests by evaluating a Starlark expression.
@@ -400,7 +400,12 @@ func (MatchNegate) CaddyModule() caddy.ModuleInfo {
// the struct, but we need a struct because we need another
// field just for the provisioned modules.
func (m *MatchNegate) UnmarshalJSON(data []byte) error {
- return json.Unmarshal(data, &m.matchersRaw)
+ return json.Unmarshal(data, &m.MatchersRaw)
+}
+
+// MarshalJSON marshals m's matchers.
+func (m MatchNegate) MarshalJSON() ([]byte, error) {
+ return json.Marshal(m.MatchersRaw)
}
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
@@ -411,21 +416,21 @@ func (m *MatchNegate) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// Provision loads the matcher modules to be negated.
func (m *MatchNegate) Provision(ctx caddy.Context) error {
- for modName, rawMsg := range m.matchersRaw {
+ for modName, rawMsg := range m.MatchersRaw {
val, err := ctx.LoadModule("http.matchers."+modName, rawMsg)
if err != nil {
return fmt.Errorf("loading matcher module '%s': %v", modName, err)
}
- m.matchers = append(m.matchers, val.(RequestMatcher))
+ m.Matchers = append(m.Matchers, val.(RequestMatcher))
}
- m.matchersRaw = nil // allow GC to deallocate
+ m.MatchersRaw = nil // allow GC to deallocate
return nil
}
// Match returns true if r matches m. Since this matcher negates the
// embedded matchers, false is returned if any of its matchers match.
func (m MatchNegate) Match(r *http.Request) bool {
- return !m.matchers.Match(r)
+ return !m.Matchers.Match(r)
}
// CaddyModule returns the Caddy module information.
@@ -686,4 +691,7 @@ var (
_ caddyfile.Unmarshaler = (*MatchHeaderRE)(nil)
_ caddyfile.Unmarshaler = (*MatchProtocol)(nil)
_ caddyfile.Unmarshaler = (*MatchRemoteIP)(nil)
+
+ _ json.Marshaler = (*MatchNegate)(nil)
+ _ json.Unmarshaler = (*MatchNegate)(nil)
)