Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jamesmcroft/traefik-plugin-rewrite-response-headers
Rewrite response headers is a middleware plugin for Traefik which rewrites the HTTP response headers by replacing a search regex by a replacement string
https://github.com/jamesmcroft/traefik-plugin-rewrite-response-headers
traefik traefik-plugin
Last synced: 28 days ago
JSON representation
Rewrite response headers is a middleware plugin for Traefik which rewrites the HTTP response headers by replacing a search regex by a replacement string
- Host: GitHub
- URL: https://github.com/jamesmcroft/traefik-plugin-rewrite-response-headers
- Owner: jamesmcroft
- License: mit
- Created: 2024-02-11T14:59:56.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-02-11T17:51:39.000Z (9 months ago)
- Last Synced: 2024-06-21T15:26:59.785Z (5 months ago)
- Topics: traefik, traefik-plugin
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rewrite Response Headers
Rewrite response headers is a middleware plugin for Traefik which rewrites the HTTP response headers by replacing a search regex by a replacement string.
## Configuration
### Static
```yaml
pilot:
token: "xxxx"experimental:
plugins:
rewriteResponseHeaders:
moduleName: github.com/jamesmcroft/traefik-plugin-rewrite-response-headers
version: "v1.0.0"
```### Dynamic
To configure the Rewrite Response Headers plugin you should create a [middleware](https://docs.traefik.io/middlewares/overview/) in your dynamic configuration as explained [here](https://doc.traefik.io/traefik/middlewares/overview/). The following example creates and uses the `rewriteResponseHeaders` middleware plugin to replace a custom `Operation-Location` header which provides a `http://` URL with a `https://` URL.
```yaml
http:
services:
serviceRoot:
loadBalancer:
servers:
- url: "http://localhost:8080"middlewares:
rewrite-operation-location-header:
plugin:
rewriteResponseHeaders:
rewrites:
- header: "Operation-Location"
regex: "^http://(.+?)/(.+)$"
replacement: "https://{RequestHost}/$2"routers:
routerRoot:
rule: "PathPrefix(`/`)"
service: "serviceRoot"
middlewares:
- "rewrite-operation-location-header"
```> [!NOTE]
> This plugin includes a `{RequestHost}` token which can be used in the `replacement` string to include the original request host in the replaced header value. **It is not required to use this token**.