plugin-rewritebody icon indicating copy to clipboard operation
plugin-rewritebody copied to clipboard

Multiple replacements?

Open C-Duv opened this issue 2 years ago • 0 comments

Does the plugin support declaring multiple replacement operations?

If want to:

  • Replace ^/foo by /xxx/foo`
  • Replace ^/bar by /xxx/bar`

(Note: I want all theses operations to occur on the body, not the first matching one)

I currently have to create/declare 2 middlewares:

[http.routers]
  [http.routers.my-router]
    rule = "Host(`localhost`)"
    middlewares = ["xxx-prefixer1", "xxx-prefixer2"]
    service = "my-service"

[http.middlewares]
  [http.middlewares.xxx-prefixer1.plugin.rewritebody]
    [[http.middlewares.xxx-prefixer1.plugin.rewritebody.rewrites]]
      regex = "foo"
      replacement = "/xxx/foo"

  [http.middlewares.xxx-prefixer2.plugin.rewritebody]
    [[http.middlewares.xxx-prefixer2.plugin.rewritebody.rewrites]]
      regex = "bar"
      replacement = "/xxx/bar"

[http.services]
  [http.services.my-service]
    [http.services.my-service.loadBalancer]
      [[http.services.my-service.loadBalancer.servers]]
        url = "http://127.0.0.1"

If I could have something like the following ([http.services] part omitted for brevity):

[http.routers]
  [http.routers.my-router]
    rule = "Host(`localhost`)"
    middlewares = ["xxx-prefixer"]
    service = "my-service"

[http.middlewares]
  [http.middlewares.xxx-prefixer.plugin.rewritebody]

    [[http.middlewares.xxx-prefixer.plugin.rewritebody.rewrites.0]]
      regex = "foo"
      replacement = "/xxx/foo"
    [[http.middlewares.xxx-prefixer.plugin.rewritebody.rewrites.1]]
      regex = "bar"
      replacement = "/xxx/bar"

It would be easier to maintain.

Thanks

C-Duv avatar Oct 20 '23 09:10 C-Duv