buger / goreplay

GoReplay is an open-source tool for capturing and replaying live HTTP traffic into a test environment in order to continuously test your system with real data. It can be used to increase confidence in code deployments, configuration changes and infrastructure changes.

Home Page:https://goreplay.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request Rewriting not working as expected with regex

Deepak1711 opened this issue Β· comments

I am using following tar: gor_1.3.3_x64.tar.gz

Gor command used:
./gor --input-raw :3000 --output-http="http://athena-service.uranus.svc.cluster.local"
--http-rewrite-url "/onemg-internal/end_user/v1/drug_skus/(\d+)/dynamic:/pharma-pdp/v1/drug/dynamic/$1"
--http-allow-url "/onemg-internal/end_user/v1/drug_skus/(\d+)/dynamic"

Request is being received at the output server, but the regex group is not captured inside $1.
Screenshot 1945-10-28 at 8 42 31 PM

As you can see in the above SS, the uri is /pharma-pdp/v1/drug/dynamic/ while it should have been /pharma-pdp/v1/drug/dynamic/1234.

Can somebody help with this?

πŸ€–

Hello @Deepak1711! πŸ‘‹

I'm Dosu, an AI bot that helps with bug-solving, Q&A, and onboarding contributors. While we're waiting for a human maintainer, I'm here to help with your GoReplay journey. Don't worry, we'll get your issue sorted out! πŸ˜ŠπŸ’»πŸš€

Based on your description, it seems like you're experiencing an issue with the --http-rewrite-url command in GoReplay v1.3.3. The regular expression group should indeed be captured inside $1 when using this command.

Your command appears to be correct:

./gor --input-raw :3000 --output-http="http://athena-service.uranus.svc.cluster.local" \
--http-rewrite-url "/__onemg-internal__/end_user/v1/drug_skus/(\d+)/dynamic:/pharma-pdp/v1/drug/dynamic/$1" \
--http-allow-url "/__onemg-internal__/end_user/v1/drug_skus/(\d+)/dynamic"

This command should rewrite all /__onemg-internal__/end_user/v1/drug_skus/<drug_id>/dynamic requests to /pharma-pdp/v1/drug/dynamic/<drug_id>.

If the regex group is not being captured correctly, it might be a bug in the version of GoReplay you're using. I would recommend updating to the latest version of GoReplay and trying again. If the problem persists, it might be worth reporting this as a bug to the GoReplay team.

The --http-rewrite-url command in GoReplay v1.3.3 is used for rewriting URLs based on a mapping. It expects a value in the ":" format, where ":" is a delimiter. In the <replace> section, you can use captured regexp group values. This works similarly to the replace method in Javascript or gsub in Ruby.

For more information, you can refer to the Request Rewriting section in the GoReplay documentation.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.

-Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a πŸ‘ if this is helpful and πŸ‘Ž if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

It seems I am already on the latest stable version. Reference: https://github.com/buger/goreplay/releases