A KrakenD HTTP client plugin that disables automatic redirect following. This plugin forces the HTTP client to return redirect responses (3xx) directly to the caller instead of automatically following them.
- Disables automatic HTTP redirect following
- Returns 3xx responses with
Locationheaders intact - Preserves all response headers and status codes
- Compatible with KrakenD 2.x
- Available for Linux AMD64 and ARM64 architectures
- KrakenD: 2.x
- Go: 1.25.6
- Platforms: Linux (amd64, arm64)
Download the latest release for your architecture:
# For AMD64
wget https://github.com/ulbwa/krakend-no-redirects-plugin/releases/latest/download/no-redirects-linux-amd64.so
# For ARM64
wget https://github.com/ulbwa/krakend-no-redirects-plugin/releases/latest/download/no-redirects-linux-arm64.soNote: The plugin must be built on Linux as it requires CGO and Linux-specific compilation.
For local development and testing, use the provided Docker setup:
git clone https://github.com/ulbwa/krakend-no-redirects-plugin.git
cd krakend-no-redirects-plugin
make buildThe compiled plugin will be available in the bin/ directory.
Mount the plugin file to /etc/krakend/plugins/ in your KrakenD container:
docker run -p 8080:8080 \
-v $PWD/no-redirects-linux-amd64.so:/etc/krakend/plugins/no-redirects.so:ro \
-v $PWD/krakend.json:/etc/krakend/krakend.json:ro \
krakend:latest run -c /etc/krakend/krakend.jsonversion: '3'
services:
krakend:
image: krakend:latest
ports:
- "8080:8080"
volumes:
- ./no-redirects-linux-amd64.so:/etc/krakend/plugins/no-redirects.so:ro
- ./krakend.json:/etc/krakend/krakend.json:ro
command: ["run", "-c", "/etc/krakend/krakend.json"]- Copy the plugin to your KrakenD plugins directory:
sudo cp no-redirects-linux-amd64.so /usr/local/lib/krakend/plugins/no-redirects.so
sudo chmod 644 /usr/local/lib/krakend/plugins/no-redirects.so- Update your KrakenD configuration to load the plugin.
Add the plugin to your krakend.json configuration:
{
"version": 3,
"plugin": {
"folder": "/etc/krakend/plugins/",
"pattern": ".so"
}
}Configure the plugin as an HTTP client for endpoints that require redirect handling:
{
"version": 3,
"endpoints": [
{
"endpoint": "/redirect-test",
"method": "GET",
"output_encoding": "no-op",
"backend": [
{
"url_pattern": "/redirect-to?url=https%3A%2F%2Fgoogle.com&status_code=302",
"host": ["https://httpbin.org"],
"encoding": "no-op",
"extra_config": {
"plugin/http-client": {
"name": "krakend-no-redirects"
}
}
}
]
}
]
}Complete Example
{
"version": 3,
"plugin": {
"folder": "/etc/krakend/plugins/",
"pattern": ".so"
},
"endpoints": [
{
"endpoint": "/api/redirect",
"method": "GET",
"output_encoding": "no-op",
"backend": [
{
"url_pattern": "/redirect-to?url=https%3A%2F%2Fgoogle.com&status_code=302",
"host": ["https://httpbin.org"],
"encoding": "no-op",
"extra_config": {
"plugin/http-client": {
"name": "krakend-no-redirects"
}
}
}
]
}
]
}When you call GET /api/redirect, the plugin will return the 302/301 response directly instead of following the redirect.
The plugin replaces KrakenD's default HTTP client with a custom client that sets CheckRedirect to return http.ErrUseLastResponse. This prevents the Go HTTP client from automatically following redirects and returns the redirect response to the caller.
- Go 1.25.6 or later
- Make
- GCC (for CGO)
make buildThe compiled plugin will be available in the bin/ directory.
Note: This plugin does not support cross-compilation. You must build on the target platform (AMD64 or ARM64) to generate the corresponding .so file. The build process automatically detects the host architecture and produces a binary for that platform only.
make cleanContributions are welcome! Please feel free to submit a Pull Request.