-
Notifications
You must be signed in to change notification settings - Fork 30
Request rewriting
Gor supports rewriting of URLs, URL params and headers, see below.
Rewriting may be useful if you test environment does not have the same data as your production, and you want to perform all actions in the context of test
user: for example rewrite all API tokens to some test value. Other possible use cases are toggling features on/off using custom headers or rewriting URL's if they changed in the new environment.
For more complex logic you can use Middleware.
--http-rewrite-url
expects value in ":" format: ":" is a dilimiter. In <replace>
section you may use captured regexp group values. This works similar to replace
method in Javascript or gsub
in Ruby.
# Rewrites all `/v1/user/<user_id>/ping` requests to `/v2/user/<user_id>/ping`
gor --input-raw :8080 --output-http staging.com --http-rewrite-url /v1/user/([^\\/]+)/ping:/v2/user/$1/ping
Set request url param, if param already exists it will be overwritten.
gor --input-raw :8080 --output-http staging.com --http-set-param api_key=1
Set request header, if header already exists it will be overwritten. May be useful if you need to identify requests generated by Gor or enable feature flagged functionality in an application:
gor --input-raw :80 --output-http "http://staging.server" \
--http-header "User-Agent: Replayed by Gor" \
--http-header "Enable-Feature-X: true"
Host header gets special treatment. By default Host get set to the value specified in --output-http. If you manually set --http-header "Host: anonther.com", Gor will not override Host value.
If you app accepts traffic from multiple domains, and you want to keep original headers, there is specific --http-original-host
with tells Gor do not touch Host header at all.
You may also read about Request filtering, Rate limiting and Middleware