diff --git a/http_modifier.go b/http_modifier.go index 5d2b3e3..b6f994c 100644 --- a/http_modifier.go +++ b/http_modifier.go @@ -5,16 +5,6 @@ import ( "hash/fnv" ) -type HTTPModifierConfig struct { - urlRegexp HTTPUrlRegexp - urlRewrite UrlRewriteMap - headerFilters HTTPHeaderFilters - headerHashFilters HTTPHeaderHashFilters - - headers HTTPHeaders - methods HTTPMethods -} - type HTTPModifier struct { config *HTTPModifierConfig } @@ -47,6 +37,15 @@ func (m *HTTPModifier) Rewrite(payload []byte) (response []byte) { } } + if m.config.urlNegativeRegexp.regexp != nil { + host, _, _, _ := proto.Header(payload, []byte("Host")) + fullPath := append(host, proto.Path(payload)...) + + if m.config.urlNegativeRegexp.regexp.Match(fullPath) { + return + } + } + if len(m.config.headerFilters) > 0 { for _, f := range m.config.headerFilters { value, s, _, _ := proto.Header(payload, f.name) diff --git a/http_modifier_settings.go b/http_modifier_settings.go index 52a8ac7..5ea8601 100644 --- a/http_modifier_settings.go +++ b/http_modifier_settings.go @@ -9,6 +9,17 @@ import ( "bytes" ) +type HTTPModifierConfig struct { + urlNegativeRegexp HTTPUrlRegexp + urlRegexp HTTPUrlRegexp + urlRewrite UrlRewriteMap + headerFilters HTTPHeaderFilters + headerHashFilters HTTPHeaderHashFilters + + headers HTTPHeaders + methods HTTPMethods +} + // // Handling of --http-allow-header options // diff --git a/settings.go b/settings.go index f540cf1..58b8400 100644 --- a/settings.go +++ b/settings.go @@ -95,9 +95,11 @@ func init() { flag.Var(&Settings.modifierConfig.methods, "output-http-method", "WARNING: `--output-http-method` DEPRECATED, use `--http-allow-method` instead") - flag.Var(&Settings.modifierConfig.urlRegexp, "http-allow-url", "A regexp to match requests against. Filter get matched agains full url with domain. Anything else will be dropped:\n\t gor --input-raw :8080 --output-http staging.com --http-filter-url ^www.") + flag.Var(&Settings.modifierConfig.urlRegexp, "http-allow-url", "A regexp to match requests against. Filter get matched agains full url with domain. Anything else will be dropped:\n\t gor --input-raw :8080 --output-http staging.com --http-allow-url ^www.") flag.Var(&Settings.modifierConfig.urlRegexp, "output-http-url-regexp", "WARNING: `--output-http-url-regexp` DEPRECATED, use `--http-allow-url` instead") + flag.Var(&Settings.modifierConfig.urlNegativeRegexp, "http-diallow-url", "A regexp to match requests against. Filter get matched agains full url with domain. Anything else will be dropped:\n\t gor --input-raw :8080 --output-http staging.com --http-disallow-url ^www.") + flag.Var(&Settings.modifierConfig.urlRewrite, "http-rewrite-url", "Rewrite the requst url based on a mapping:\n\tgor --input-raw :8080 --output-http staging.com --http-rewrite-url /v1/user/([^\\/]+)/ping:/v2/user/$1/ping") flag.Var(&Settings.modifierConfig.urlRewrite, "output-http-rewrite-url", "WARNING: `--output-http-rewrite-url` DEPRECATED, use `--http-rewrite-url` instead")