{"id":13564375,"url":"https://github.com/packruler/rewrite-body","last_synced_at":"2026-01-29T21:08:35.375Z","repository":{"id":37003213,"uuid":"482376325","full_name":"packruler/rewrite-body","owner":"packruler","description":"Traefik Plugin to allow regex replacement of HTTP GET response body","archived":false,"fork":false,"pushed_at":"2024-05-20T10:59:27.000Z","size":666,"stargazers_count":28,"open_issues_count":3,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-10T09:07:36.028Z","etag":null,"topics":["traefik","traefik-plugin","traefik-v2"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/packruler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-16T22:40:29.000Z","updated_at":"2025-08-29T19:33:07.000Z","dependencies_parsed_at":"2024-01-14T03:48:42.649Z","dependency_job_id":"1a01f439-709e-4f58-9882-10b7c2d7f267","html_url":"https://github.com/packruler/rewrite-body","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/packruler/rewrite-body","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packruler%2Frewrite-body","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packruler%2Frewrite-body/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packruler%2Frewrite-body/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packruler%2Frewrite-body/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/packruler","download_url":"https://codeload.github.com/packruler/rewrite-body/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packruler%2Frewrite-body/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28884969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T21:06:44.224Z","status":"ssl_error","status_checked_at":"2026-01-29T21:06:42.160Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["traefik","traefik-plugin","traefik-v2"],"created_at":"2024-08-01T13:01:30.370Z","updated_at":"2026-01-29T21:08:35.355Z","avatar_url":"https://github.com/packruler.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Rewrite Body\n\nThis is a fork of [Traefik](https://github.com/traefik)'s [plugin-rewritebody](https://github.com/traefik/plugin-rewritebody)\nthat is aimed at extending support to handle `gzip` content. This was initially aimed at extending the support for utilizing\n[theme.park](https://github.com/traefik/plugin-rewritebody)'s themes but can likely be used for a range of other uses.\n\n## Changes From Original Traefik Plugin\n\nThe primary change is to add support for `gzip` content. This brought another potential issue to mind, what about really large\ncontent? This was handled as well.\n\n### Process For Handling Body Content\n\n#### Body Content Requirements\n\n* The header must have `Content-Type` that includes `text`. For example:\n  * `text/html`\n  * `text/json`\n* The header must have `Content-Encoding` header that is supported by this plugin\n  * The original plugin supported `Content-Encoding` of `identity` or empty\n  * This plugin adds support for `gzip` and `zlib` encoding\n\n#### Processing Paths\n\n* If the either of the previous conditions failes the body is passed on as is and no further processing from this plugin occurs.\n\n* If the `Content-Encoding` is empty or `identity` it is handled in mostly the same manner as the original plugin.\n\n* If the `Content-Encoding` is `gzip` the following process happens:\n  * The body content is decompressed by [Go-lang's gzip library](https://pkg.go.dev/compress/gzip)\n  * The resulting content is run through the `regex` process created by the original plugin\n  * The processed content is then compressed with the same library and returned\n\n## Configuration\n\n### Static\n\n```yaml\npilot:\n  token: \"xxxx\"\n\nexperimental:\n    plugins:\n        rewrite-body:\n            moduleName: \"github.com/packruler/rewrite-body\"\n            version: \"v1.1.0\"\n```\n\n### Dynamic\n\nTo configure the `Rewrite Body` plugin you should create a [middleware](https://docs.traefik.io/middlewares/overview/) in \nyour dynamic configuration as explained [here](https://docs.traefik.io/middlewares/overview/). The following example creates\nand uses the `rewritebody` middleware plugin to replace all foo occurences by bar in the HTTP response body.\n\nIf you want to apply some limits on the response body, you can chain this middleware plugin with the [Buffering middleware](https://docs.traefik.io/middlewares/buffering/) from Traefik.\n\n```yaml\nhttp:\n  routers:\n    my-router:\n      rule: \"Host(`localhost`)\"\n      middlewares: \n        - \"rewrite-foo\"\n      service: \"my-service\"\n\n  middlewares:\n    rewrite-foo:\n      plugin:\n        rewrite-body:\n          # Keep Last-Modified header returned by the HTTP service.\n          # By default, the Last-Modified header is removed.\n          lastModified: true\n\n          # Rewrites all \"foo\" occurences by \"bar\"\n          rewrites:\n            - regex: \"foo\"\n              replacement: \"bar\"\n\n          # logLevel is optional, defaults to Info level.\n          # Available logLevels: (Trace: -2, Debug: -1, Info: 0, Warning: 1, Error: 2)\n          logLevel: 0\n\n          # monitoring is optional, defaults to below configuration\n          # monitoring configuration limits the HTTP queries that are checked for regex replacement.\n          monitoring:\n            # methods is a string list. Options are standard HTTP Methods. Entries MUST be ALL CAPS\n            # For a list of options: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods\n            methods:\n              - GET\n            # types is a string list. Options are HTTP Content Types. Entries should match standard formatting\n            # For a list of options: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types\n            # Wildcards(*) are not supported!\n            types:\n              - text/html\n  services:\n    my-service:\n      loadBalancer:\n        servers:\n          - url: \"http://127.0.0.1\"\n```\n\n## Example theme.park\n\n### Dynamic\n\n```yaml\nhttp:\n  routers:\n    sonarr-router:\n      rule: \"Host(`sonarr.example.com`)\"\n      middlewares: \n        - sonarr-theme\n      service: sonarr-service\n\n  middlewares:\n    sonarr-theme:\n      plugin:\n        rewrite-body:\n          rewrites:\n            - regex: \u003c/head\u003e\n              replacement: \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"https://theme-park.dev/css/base/sonarr/{{ env \"THEME\" }}.css\"\u003e\u003c/head\u003e\n\n  services:\n    sonarr-service:\n      servers:\n        - url: http://localhost:8989\n```\n\nYou can set an environment variable `THEME` to the name of a theme for easier consistency across apps.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpackruler%2Frewrite-body","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpackruler%2Frewrite-body","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpackruler%2Frewrite-body/lists"}