Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to replace all instances of a given string in request header #72

Open
jvanheesch opened this issue Jun 3, 2024 · 3 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@jvanheesch
Copy link

Reproducer can be found here.

I am unable to replace all instances of a given string input with replacement value output.
I checked the source code, but could not come up with a different config that would achieve the desired result.
As a workaround, we currently resort to adding multiple instances of the exact same RewriteValueRule.

@tomMoulard
Copy link
Owner

Hello @jvanheesch,

Thanks for your interest in this Traefik Plugin !

What do you mean when you say:

I am unable to replace all instances of a given string input with replacement value output.

By all instances, do you mean that you have multiple headers where you want to replace the value.

like

Replace:

$ > curl -I https://example.com
HTTP/2 200 
accept-ranges: bytes
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
content-type: text/html
date: Mon, 03 Jun 2024 15:31:59 GMT
etag: "5fd8e6de-690f"
X-Forwarded-For: 10.0.0.0
X-Real-IP: 10.0.0.0

To:

$ > curl -I https://google.com
HTTP/2 200 
accept-ranges: bytes
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
content-type: text/html
date: Mon, 03 Jun 2024 15:31:59 GMT
etag: "5fd8e6de-690f"
X-Forwarded-For: 11.0.0.0
X-Real-IP: 11.0.0.0

This is possible by using a plugin configuration that could look like this:

- Rule:
      Name: 'Header rewriteValue'
      Header: 'X-(Real-IP|Forwarded-For)'
      Value: '10.(.*)'
      ValueReplace: '11.$1'
      Type: 'RewriteValueRule'

Or do you mean that you have multiple instance of the value in a single header value ?

like

Replace:

$ > curl -I https://example.com
HTTP/2 200 
accept-ranges: bytes
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
content-type: text/html
date: Mon, 03 Jun 2024 15:31:59 GMT
etag: "5fd8e6de-690f"
X-Forwarded-For: 10.0.0.0

To:

$ > curl -I https://google.com
HTTP/2 200 
accept-ranges: bytes
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
content-type: text/html
date: Mon, 03 Jun 2024 15:31:59 GMT
etag: "5fd8e6de-690f"
X-Forwarded-For: 10.42.42.42

@tomMoulard tomMoulard added the contributor/waiting-for-feedback Feedback from the contributor is needed label Jun 3, 2024
@jvanheesch
Copy link
Author

@tomMoulard Thank you for the quick response!

I am trying the second, i.e. replacing multiple (all) instances of a string in a single header value.
I've created a reproducer, which can be found here, to share my config + actual/expected behavior.
Please let me know if you have any further questions!

@tomMoulard
Copy link
Owner

Indeed the could be a good fix to add to the RewriteValueRule handler!

@tomMoulard tomMoulard added enhancement New feature or request good first issue Good for newcomers and removed contributor/waiting-for-feedback Feedback from the contributor is needed labels Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants