https://github.com/redhoyasa/kong-plugin-route-by-cookie
Kong plugin to dynamically change upstream url based on cookies 🍪
https://github.com/redhoyasa/kong-plugin-route-by-cookie
cookies kong kong-plugin
Last synced: 6 months ago
JSON representation
Kong plugin to dynamically change upstream url based on cookies 🍪
- Host: GitHub
- URL: https://github.com/redhoyasa/kong-plugin-route-by-cookie
- Owner: redhoyasa
- License: mit
- Created: 2019-09-18T09:13:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-20T12:04:28.000Z (almost 5 years ago)
- Last Synced: 2025-03-07T14:11:33.432Z (7 months ago)
- Topics: cookies, kong, kong-plugin
- Language: Lua
- Homepage:
- Size: 19.5 KB
- Stars: 8
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kong-plugin-route-by-cookie
Kong plugin for dynamically change upstream url based on cookies.## Overview
This Kong plugin allows you to route client request based on user cookies. It is inspired by [Route By Header](https://docs.konghq.com/hub/kong-inc/route-by-header/).
## Usage
### Enabling the plugin on a Service
```
curl -X POST http://kong:8001/services/{service}/plugins \
--data "name=route-by-cookie" \
--data "config.target_upstream=new-upstream" \
--data "config.cookie_name=COOKIE_NAME" \
--data "config.cookie_val=value"
```### Enabling the plugin on a Route
```
curl -X POST http://kong:8001/routes/{route_id}/plugins \
--data "name=route-by-cookie" \
--data "config.target_upstream=new-upstream" \
--data "config.cookie_name=COOKIE_NAME" \
--data "config.cookie_val=value"
```### Config
- `target_upstream`: Kong Upstream which we want to route the request to
- `config.cookie_name`: Cookie name which we will check at
- `config.cookie_val`: If user's cookie value equals this, Kong will route the user to `target_upstream`## Supported Kong Releases
Kong >= 2.0
Should work with 1.X but not tested
## Installation
```
luarocks install kong-plugin-route-by-cookie
```## Tests
You need [Pongo](https://github.com/Kong/kong-pongo) to run the tests.
```
pongo run
```
Expected output:
```
Kong version: 2.2.0
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
49 successes / 0 failures / 0 errors / 0 pending : 5.379104 seconds
```## Maintainers
[redhoyasa](https://github.com/redhoyasa)
[utix](https://github.com/utix)