Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy server feature #33

Closed
joanlopez opened this issue Oct 14, 2019 · 3 comments
Closed

Proxy server feature #33

joanlopez opened this issue Oct 14, 2019 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers Hacktoberfest
Milestone

Comments

@joanlopez
Copy link
Member

joanlopez commented Oct 14, 2019

Context

One of the most requested features by our users is to implement a "proxy server" feature
(reasons below).

On the one hand, as the mock server is something you need to build up (provide) as you develop your API, sometimes there are some endpoints that are not already defined on the mock server configuration, so you might want to let the mock do a request to the "real" implementation when that happens.

OTOH, you might even want to have a "flag" that allows you to switch on-off the mock server.

Proposed implementation

Both situations can be solved by providing a configuration section named proxy_server with two attributes.

  • The first one named mode (or similar) with the following choices:

    • all (all the requests will be redirected)
    • missing (only the missing requests will be redirected)
    • none -or off (no proxy, default value).
  • The second one named base_url (or similar) to configure the origin of the "real" implementation.

For the proxy's implementation itself, there are many examples over internet about how to implement a proxy server with Go. Ideally, we won't want to add new third-party dependencies.

Any suggestion about that will be welcome.

@joanlopez joanlopez added enhancement New feature or request good first issue Good for newcomers Hacktoberfest labels Oct 14, 2019
@aperezg aperezg added this to the v0.4.0 milestone Oct 15, 2019
@Darkclainer
Copy link
Contributor

Darkclainer commented Oct 16, 2019

The most important concern here is flexibility in my opinion. But I think we can for now stick to proposed behaviour, it seems not very difficult to make more fine-grained control if users will need this (for example, they may want to have option for each endpoint - is it mandatory proxied or not).

Technical detail about implementation proposed above:
Add to server new field - proxy, that will contain it configuration and detail for actual implementation
Add in server.Build method at the end new route matcher:

s.router.PathPrefix("/").Handler(proxyHandler)

Proxy implementation can reside in separate file.
Also we can use standard httputil.ReverseProxy if I correctly understand the proposal. It allows to read and modify response, so we can later use in issue #34

@joanlopez
Copy link
Member Author

Yeah! That sounds really good!

Regarding the httputil.ReverseProxy, I never had the oportunity to play with it, but I'd vote for it as the first option (also for #34) as it'd avoid us from having to add new third-party dependencies.

Finally, I'd go for a simple proxy implementation (and keeping Killgrave simple). I wouldn't give "too much" flexibility if it does not worth for users (not requested by them).

Thanks for your contributions 😇

@aperezg
Copy link
Member

aperezg commented Jan 30, 2020

Closes #41

@aperezg aperezg closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants