| 15 | var _ ConditionModifier = (*MethodModifier)(nil) |
| 16 | |
| 17 | func (m *MethodModifier) Parse(modifier string) error { |
| 18 | eqIndex := strings.IndexByte(modifier, '=') |
| 19 | if eqIndex == -1 { |
| 20 | return fmt.Errorf("invalid method modifier") |
| 21 | } |
| 22 | value := modifier[eqIndex+1:] |
| 23 | |
| 24 | m.inverted = strings.HasPrefix(value, "~") |
| 25 | entries := strings.Split(value, "|") |
| 26 | m.entries = make([]methodModifierEntry, len(entries)) |
| 27 | for i, entry := range entries { |
| 28 | if entry == "" { |
| 29 | return errors.New("empty method modifier entry") |
| 30 | } |
| 31 | inverted := strings.HasPrefix(entry, "~") |
| 32 | if inverted != m.inverted { |
| 33 | return errors.New("cannot mix inverted and non-inverted method modifiers") |
| 34 | } |
| 35 | if inverted { |
| 36 | entry = entry[1:] |
| 37 | } |
| 38 | |
| 39 | m.entries[i] = methodModifierEntry{} |
| 40 | m.entries[i].Parse(entry) |
| 41 | } |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | func (m *MethodModifier) ShouldMatchReq(req *http.Request) bool { |
| 46 | matches := false |