-
Notifications
You must be signed in to change notification settings - Fork 100
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
Add proxy server feature. #41
Conversation
Now in configuration in "proxy" section you can specify two new options: 1. url - is a proxy url 2. mode - it is string, one of "all", "missing", "none"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found some fixes!
P.S. share your ideas, feedbacks or issues with us at https://github.com/fixmie/feedback (this message will be removed after the beta stage).
internal/config.go
Outdated
type ProxyMode int | ||
|
||
const ( | ||
// Proxy server is off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existing comment doesn't match identifier "ProxyNone"
// Proxy server is off | |
// ProxyNone server is off |
internal/config.go
Outdated
const ( | ||
// Proxy server is off | ||
ProxyNone ProxyMode = iota | ||
// Only missing requests are proxied |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existing comment doesn't match identifier "ProxyMissing"
// Only missing requests are proxied | |
// ProxyMissing missing requests are proxied |
internal/config.go
Outdated
ProxyNone ProxyMode = iota | ||
// Only missing requests are proxied | ||
ProxyMissing | ||
// All requests are proxied |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existing comment doesn't match identifier "ProxyAll"
// All requests are proxied | |
// ProxyAll requests are proxied |
Codecov Report
@@ Coverage Diff @@
## master #41 +/- ##
========================================
+ Coverage 91% 92.3% +1.3%
========================================
Files 6 7 +1
Lines 189 221 +32
========================================
+ Hits 172 204 +32
Misses 14 14
Partials 3 3
Continue to review full report at Codecov.
|
Can you check it, @joanlopez? |
internal/config.go
Outdated
} | ||
|
||
// ProxyMode is enumeration of proxy server modes | ||
type ProxyMode int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type ProxyMode int | |
type ProxyMode uint8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need specifically uint8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we prefer declare the enums with a more accurate type possible as standard, 8bits is more than enough to a enum and in most case u don't need negative numbers, so uint8
is a elegant solution
Co-Authored-By: Adrian Perez <[email protected]>
// Handler returns handler that sends request to another server. | ||
func (p *Proxy) Handler() http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
p.server.ServeHTTP(w, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to update the headers to allow for SSL redirection:
r.URL.Host = p.url.Host
r.URL.Scheme = p.url.Scheme
r.Header.Set("X-Forwarded-Host", r.Header.Get("Host"))
r.Host = p.url.Host
For that you will need to persist the result of url.Parse into the proxy struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with the comment that I suggested and, all working very fine :)
All options that we include on the config file, usually are on the command line also. I think that you could add something like that: And if the |
Could you update the README.md with how to use the proxy? In the section Using Killgrave Below to the sentence: "Or custome your server with this flags:" we're printing an output of the help command, so when you've added your new flags, you will need to update this with your output, as now. And in the section "Use Modify the example with the proxy, i.e: #config.yml
imposters_path: "imposters"
port: 3000
host: "localhost"
proxy:
url: https://example.com
mode: missing
cors:
methods: ["GET"]
headers: ["Content-Type"]
exposed_headers: ["Cache-Control"]
origins: ["*"]
allow_credentials: true And if you want you could include a section like #CORS section, where you explain how the proxy works and which are the options to configure the proxy. Thanks! |
Follow #44 |
Now in configuration in "proxy" section you can specify two new options:
Issue #33