| 27 | var _ ConditionModifier = (*DomainModifier)(nil) |
| 28 | |
| 29 | func (m *DomainModifier) Parse(modifier string) error { |
| 30 | eqIndex := strings.IndexByte(modifier, '=') |
| 31 | if eqIndex == -1 || eqIndex == len(modifier)-1 { |
| 32 | return errors.New("invalid domain modifier") |
| 33 | } |
| 34 | value := modifier[eqIndex+1:] |
| 35 | |
| 36 | m.inverted = strings.HasPrefix(value, "~") |
| 37 | matches := domainModifierRegex.FindAllString(value, -1) |
| 38 | m.entries = make([]domainModifierEntry, len(matches)) |
| 39 | for i, entry := range matches { |
| 40 | inverted := len(entry) > 0 && entry[0] == '~' |
| 41 | if inverted != m.inverted { |
| 42 | return errors.New("cannot mix inverted and non-inverted method modifiers") |
| 43 | } |
| 44 | if inverted { |
| 45 | entry = entry[1:] |
| 46 | } |
| 47 | |
| 48 | m.entries[i] = domainModifierEntry{} |
| 49 | if err := m.entries[i].Parse(entry); err != nil { |
| 50 | return fmt.Errorf("parse entry %q: %w", entry, err) |
| 51 | } |
| 52 | } |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | func (m *DomainModifier) ShouldMatchReq(req *http.Request) bool { |
| 57 | var hostname string |