Skip to content

mykaarma/kong-set-upstream-by-header

Repository files navigation

kong-set-upstream-by-header

This plugin sets the upstream of the request in Kong on the basis of header.

Installation

Using Luarocks:
The plugin can be installed by using the following command:
luarocks install set-upstream-by-header

Using source:
git clone https://github.com/mykaarma/kong-set-upstream-by-header
cd kong-set-upstream-by-header
luarocks make

Then, add the plugin to the plugins key in kong.conf file.
plugins=set-upstream-by-header

Parameters

Here's a list of all the parameters which can be used in this plugin's configuration:

Parameter Required Description
name true The name of the plugin to use, in this case set-upstream-by-header
config.header true The name of the header whose is need to be considered for routing
config.header_value_and_upstream_map true The mapping of the header value with the desired upstream to which the request is to be routed. It should be provided as a map.
header_matching true It takes one of the following values: exact or regex.
If it is set to exact, then the exact header value should be provided in the mapping.
If it is set to regex, then the regex of the header value should be provided in the mapping.
default_upstream true If the given header is not present or matched, then the request is routed to this upstream.

How to apply?

The plugin can be applied using Kong Admin API as follows:

curl -X POST <Kong-Admin-API-URL>/plugins \
--data "name=set-upstream-by-header" \
--data "config.header=<header>" \
--data "config.header_value_and_upstream_map.<header-value-1>=<upstream-1>" \
--data "config.header_value_and_upstream_map.<header-value-2>=<upstream-2>" \
--data "config.header_matching=regex" \
--data "config.default_upstream=<default-upstream>

For example: Routing on the basis of header cookie

curl -X POST <Kong-Admin-API-URL>/plugins \
--data "name=set-upstream-by-header" \
--data "config.header=cookie" \
--data "config.header_value_and_upstream_map.rollout_stage_canary=canary-upstream" \
--data "config.header_value_and_upstream_map.rollout_stage_stable=stable-upstream" \
--data "config.header_matching=regex" \
--data "config.default_upstream=stable-upstream

About

Plugin to route at kong level based on header value

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •