smocker-dev / smocker

Smocker is a simple and efficient HTTP mock server and proxy
https://smocker.dev
MIT License
1.16k stars 61 forks source link

Dynamic proxy? #298

Open Laski opened 9 months ago

Laski commented 9 months ago

I'm trying to combine the "dynamic_mock" and "proxy" resources. My objective is to route the requests wherever the HOST header says.

e.g.

request:
  method: GET
  path: /example
dynamic_response:
  engine: lua
  script: |-
    require "math"
    return {
      proxy = {
        host = ..request.headers.host,
        follow_redirects = true
      }
    }

or

request:
  method: GET
  path: /example
dynamic_response:
  engine: go_template_yaml
  script: |
    proxy:
      host: {{.Request.Headers.Get "Host"}}
      follow_redirect: true

neither of this seem to work (the response is actually 200 but empty).

Maybe I should note that hardcoding the host part doesn't seem to work either.

Is this a supported use case?

Thiht commented 8 months ago

Hi @Laski,

dynamic_responses only allow to generate a response, not a proxy.

There's no real way to handle "dynamic proxy" for now.