@@ -63,25 +63,10 @@ func Handler(w http.ResponseWriter, r *http.Request, c *config.Config, logger lo
63
63
return
64
64
}
65
65
66
- if module .HTTP .EnableRegexpsFromParams {
67
- var err error
68
- paramRegexps , err := extractHTTPParamRegexps (params )
69
- if err != nil {
70
- http .Error (w , fmt .Sprintf ("Failed to extract regular expressions from params: %s" , err ), http .StatusBadRequest )
71
- return
72
- }
73
- if paramRegexps .FailIfBodyMatchesRegexp != nil {
74
- module .HTTP .FailIfBodyMatchesRegexp = append (module .HTTP .FailIfBodyMatchesRegexp , * paramRegexps .FailIfBodyMatchesRegexp )
75
- }
76
- if paramRegexps .FailIfBodyNotMatchesRegexp != nil {
77
- module .HTTP .FailIfBodyNotMatchesRegexp = append (module .HTTP .FailIfBodyNotMatchesRegexp , * paramRegexps .FailIfBodyNotMatchesRegexp )
78
- }
79
- if paramRegexps .FailIfHeaderMatchesRegexp != nil {
80
- module .HTTP .FailIfHeaderMatchesRegexp = append (module .HTTP .FailIfHeaderMatchesRegexp , * paramRegexps .FailIfHeaderMatchesRegexp )
81
- }
82
- if paramRegexps .FailIfHeaderNotMatchesRegexp != nil {
83
- module .HTTP .FailIfHeaderNotMatchesRegexp = append (module .HTTP .FailIfHeaderNotMatchesRegexp , * paramRegexps .FailIfHeaderNotMatchesRegexp )
84
- }
66
+ err := module .HTTP .AddRegexpsFromParams (params )
67
+ if err != nil {
68
+ http .Error (w , fmt .Sprintf ("Failed to parse regexps from URL parameters: %s" , err ), http .StatusBadRequest )
69
+ return
85
70
}
86
71
87
72
timeoutSeconds , err := getTimeout (r , module , timeoutOffset )
@@ -160,69 +145,6 @@ func Handler(w http.ResponseWriter, r *http.Request, c *config.Config, logger lo
160
145
h .ServeHTTP (w , r )
161
146
}
162
147
163
- func extractHTTPParamRegexps (params url.Values ) (* config.HTTPRegexps , error ) {
164
- var (
165
- dynamicHTTPRegexps config.HTTPRegexps
166
- err error
167
- )
168
-
169
- if re := params .Get ("fail_if_body_matches_regexp" ); re != "" {
170
- dynamicHTTPRegexps .FailIfBodyMatchesRegexp , err = regexpFromURLEncodedString (re )
171
- if err != nil {
172
- return nil , fmt .Errorf ("failed to parse fail_if_body_matches_regexp: %s" , err )
173
- }
174
- }
175
- if re := params .Get ("fail_if_body_not_matches_regexp" ); re != "" {
176
- dynamicHTTPRegexps .FailIfBodyNotMatchesRegexp , err = regexpFromURLEncodedString (re )
177
- if err != nil {
178
- return nil , fmt .Errorf ("failed to parse fail_if_body_not_matches_regexp: %s" , err )
179
- }
180
- }
181
- if re := params .Get ("fail_if_header_matches_regexp" ); re != "" {
182
- dynamicHTTPRegexps .FailIfHeaderMatchesRegexp , err = extractHeaderMatch (
183
- params .Get ("fail_if_header_matches_regexp_header" ), re )
184
- if err != nil {
185
- return nil , fmt .Errorf ("failed to parse %s: %s" , "fail_if_header_matches_regexp" , err )
186
- }
187
- }
188
- if re := params .Get ("fail_if_header_not_matches_regexp" ); re != "" {
189
- dynamicHTTPRegexps .FailIfHeaderNotMatchesRegexp , err = extractHeaderMatch (re , "fail_if_header_not_matches_regexp" )
190
- if err != nil {
191
- return nil , fmt .Errorf ("failed to parse %s: %s" , "fail_if_header_matches_regexp" , err )
192
- }
193
- }
194
- return & dynamicHTTPRegexps , nil
195
- }
196
-
197
- func extractHeaderMatch (headerParam , headerRegexpParam string ) (* config.HeaderMatch , error ) {
198
- var dynamicHeaderMatch config.HeaderMatch
199
- var err error
200
-
201
- if headerParam == "" || headerRegexpParam == "" {
202
- return nil , fmt .Errorf ("both fail_if_header_matches_regexp and fail_if_header_matches_regexp_header must be specified" )
203
- }
204
-
205
- dynamicHeaderMatch .Header = headerParam
206
- regexp , err := regexpFromURLEncodedString (headerRegexpParam )
207
- if err != nil {
208
- return nil , fmt .Errorf ("failed to parse %s: %s" , headerRegexpParam , err )
209
- }
210
- dynamicHeaderMatch .Regexp = * regexp
211
- return & dynamicHeaderMatch , err
212
- }
213
-
214
- func regexpFromURLEncodedString (a string ) (* config.Regexp , error ) {
215
- re , err := url .QueryUnescape (a )
216
- if err != nil {
217
- return nil , fmt .Errorf ("failed to unescape regexp: %s" , err )
218
- }
219
- regexp , err := config .NewRegexp (re )
220
- if err != nil {
221
- return nil , fmt .Errorf ("failed to compile regexp: %s" , err )
222
- }
223
- return & regexp , nil
224
- }
225
-
226
148
func setHTTPHost (hostname string , module * config.Module ) error {
227
149
// By creating a new hashmap and copying values there we
228
150
// ensure that the initial configuration remain intact.
0 commit comments