-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow host #85
Allow host #85
Conversation
Hi, What was the r.Host variable set to in your case? What was the difference with r.RemoteAddr? Is that because it does DNS resolution? Could we use |
r.Host has the style of localip:port, allowedHost is the clair 'host ip, they are not match. |
I think that's why @Quentin-M is suggesting changing if strings.HasPrefix(r.RemoteAddr, allowedHost) {
http.FileServer(http.Dir(path)).ServeHTTP(w, r)
return to host := net.SplitHostPort(r.RemoteAddr)
if strings.EqualFold(host, allowedHost) {
http.FileServer(http.Dir(path)).ServeHTTP(w, r)
return |
yes, I think so,updated,thank you. |
@@ -257,7 +258,8 @@ func listenHTTP(path, allowedHost string) { | |||
|
|||
restrictedFileServer := func(path, allowedHost string) http.Handler { | |||
fc := func(w http.ResponseWriter, r *http.Request) { | |||
if r.Host == allowedHost { | |||
host, _, err := net.SplitHostPort(r.RemoteAddr) | |||
if nil == err && strings.EqualFold(host, allowedHost) { |
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.
Can you reorder this to if err == nil && ...
? It's idiomatic to write the error check in this order in Go.
Signed-off-by: yangshukui <[email protected]>
Thanks @keloyang! I'm going to try it as soon as possible and then merge it. |
It works fine with docker-machine on OSX! LGTM. |
"r.Host == allowedHost" is not available for testing the func of clair when clair and analyze-local-images are not in the same host, and if the fileserver want clair to access,itshould use RemoteAddr to determine which host can access