Kong: Ability to duplicated headers in 'request-transformer'

Created on 15 Jul 2016  路  5Comments  路  Source: Kong/kong

We usually run into situations in which we have applications that expect certain values (e.g., consumer identity) in a special header. While we have authentication plugins that use both Kong's standard headers (e.g., consumer-custom-id) and our own headers, when using some other authentication plugins such as basic-auth we can't override this. In these scenarios, it would be desirable to be able to duplicate a header with a different header name.

This would be something like this:

  • A new configuration value for the plugin, say config.duplicate.headers=x-consumer-custom-id|x-foo-bar-duplicate-custom-id, h1|h2, ..., where the | acts as a delimiting character (there might be a better one... something that is typically not present in headers?)
  • The new order of execution would be: duplicate --> remove --> replace --> add --> append (so that you can decide to remove the old header if needed, thus implementing a "rename")
good first issue tasfeature

Most helpful comment

@jmdacruz @thefosk @thibaultcha how about instead of adding a new config like config.duplicate.headers, we support parameters to all existing relevant configs like

config.replace.headers={"h1:${refer another header}", "h1:v2", "h2:v1"}

All 5 comments

@jmdacruz @thefosk @thibaultcha how about instead of adding a new config like config.duplicate.headers, we support parameters to all existing relevant configs like

config.replace.headers={"h1:${refer another header}", "h1:v2", "h2:v1"}

Looks good to me, and it might be an even easier fix too. It might also me more powerful in the sense that you can rewrite headers, etc. I'm wondering if such "expression language" would be worth considering, e.g., using regular expressions for replacements (a la Bash replacements on environment variables)

This would make migrating to Kong a little smoother

Guys, do we have any workaround for this?
I'm having the same requirement where I want to replace header from another header, Any Idea how or when we are getting for this?

We can use config.rename.headers to achieve this.

--data "config.rename.headers=header1:header2"

I started looking into code how it's writing to understand if It's possible to pass the header1 variable for header2.
https://github.com/Kong/kong/blob/master/kong/plugins/request-transformer/access.lua

I noticed there is some code for rename header "-- Rename headers(s)" which is not there in the documentation. It is doing kind of both things what I was looking.

First, replace the new value from Header1 to Header2 and then scrapping the header1. (In other words Rename :p)

Best Regards,
Tayyab Khan

Was this page helpful?
0 / 5 - 0 ratings