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

Allow host #85

Merged
merged 1 commit into from
Mar 9, 2016
Merged

Allow host #85

merged 1 commit into from
Mar 9, 2016

Conversation

keloyang
Copy link

@keloyang keloyang commented Mar 2, 2016

"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

@Quentin-M
Copy link
Contributor

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 net.SplitHostPort(r.RemoteAddr) instead of strings.HasPrefix(r.RemoteAddr, ...)?

@keloyang
Copy link
Author

keloyang commented Mar 4, 2016

r.Host has the style of localip:port, allowedHost is the clair 'host ip, they are not match.

@jzelinskie
Copy link
Contributor

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

@keloyang
Copy link
Author

keloyang commented Mar 8, 2016

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) {
Copy link
Contributor

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 <yangshukui@huawei.com>
@Quentin-M
Copy link
Contributor

Thanks @keloyang! I'm going to try it as soon as possible and then merge it.

@Quentin-M
Copy link
Contributor

It works fine with docker-machine on OSX! LGTM.
Sorry for the delay and thanks for the contribution!

Quentin-M added a commit that referenced this pull request Mar 9, 2016
@Quentin-M Quentin-M merged commit 81363b4 into quay:master Mar 9, 2016
@jzelinskie jzelinskie added kind/bug things are not as they seem reviewed/lgtm labels Mar 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug things are not as they seem
Development

Successfully merging this pull request may close these issues.

None yet

3 participants