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

Set header from the value of another header (logic already exists in Join) #73

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

Comments

@shmuelarditi
Copy link

shmuelarditi commented Jun 6, 2024

Hi, @tomMoulard first of all thanks for creating this plugin we are using it in a few places and its great.

we would be happy if we could set an header based on another header value, for example using:

- name: ip-country-headers
  spec:
    plugin:
      htransformation:
        Rules:
        - Name: copy cf-connecting-ip value to new header cf-original-connecting-ip
          type: Set
          HeaderPrefix: "^"
          header: Client-Original-Connecting-Ip
          value: "^Cf-Connecting-Ip"

        - Name: copy cf-connecting-ip value to new header cf-original-connecting-ip
          type: Set
          HeaderPrefix: "^"
          header: Client-Original-Country
          value: "^Cf-Ipcountry"

it will be a great and very useful addition, and considering there is similar logic in the Join handler i hope it wont be much work.

@shmuelarditi
Copy link
Author

UPDATE:

i was able to archive this using a workaround, example:

- name: ip-country-headers
  spec:
    plugin:
      htransformation:
        Rules:
        - Name: 'Initialize Client-Original-Connecting-Ip'
          Header: 'Client-Original-Connecting-Ip'
          Value: ''  # Setting it to empty
          Type: 'Set'

        - Name: 'Copy CF-Connecting-Ip'
          Header: 'Client-Original-Connecting-Ip'
          HeaderPrefix: '^'
          Sep: ' ' #cant use empty separators so just use space, it will remove it
          Values:
              - '^Cf-Connecting-Ip'
          Type: 'Join'

result from a dummy service i created on our k8s that prints headers:

"cf-connecting-ip": "176.231.166.59",
"client-original-connecting-ip": "176.231.166.59",

would still appreciate adding this feature to the SET handler, as this workout is working but a bit ugly :)

@tomMoulard tomMoulard added the question Further information is requested label Jun 6, 2024
@tomMoulard
Copy link
Owner

Hello @shmuelarditi,

Thanks for your interest in this traefik plugin !

Indeed, this workaround exists, and might not be the best solution for this.

Feel free to open a PR to add this new feature in the Set Handler 😄

@tomMoulard tomMoulard added enhancement New feature or request good first issue Good for newcomers and removed question Further information is requested labels Jun 6, 2024
@redge76
Copy link

redge76 commented Oct 1, 2024

I have found that the white space is not "removed", you have use the following code to copy a header to another one:

    mw-cf-copy-user-to-X-Forwarded-User:
      plugin:
        htransformation:
          Rules:
          - Name: 'Initialize X-Forwarded-User'
            Header: 'X-Forwarded-User'
            Value: ''  # Setting it to empty
            Type: 'Set'

          - Name: 'Copy cf-Access-Authenticated-User-Email'
            Header: 'X-Forwarded-User'
            HeaderPrefix: '^'
            Sep: ' ' #cant use empty separators so just use space, it will remove it
            Values:
              - '^Cf-Access-Authenticated-User-Email'
            Type: 'Join'

          - Name: 'Remove empty space'
            Header: 'X-Forwarded-User'
            Value: ' (.*)'
            ValueReplace: '$1'
            Type: 'RewriteValueRule'

@georglauterbach
Copy link

I'd like to see this as well :)

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

4 participants