-
Notifications
You must be signed in to change notification settings - Fork 156
Set fake host header for local communication. #190
Conversation
3f8c05e
to
1376e4b
Compare
Would it be possible to add a testcase for this to make sure we don't change it (or remove it) by accident? |
@duglin Sure, will do that soon. Thanks! |
1376e4b
to
efcd30b
Compare
@duglin Addressed comments. |
}, | ||
{ | ||
"tcp://0.0.0.0:4243", | ||
"", |
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.
Even though the PR is focused on the ""
case, let's make the testcase cover the "normal" host cases too. Can you please add a test variant where test.expectedHost
isn't ""
?
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.
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.
Oh, wait, let me see.
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.
wouldn't using "tcp://localhost:4243" do it?
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.
No. The request.Host
is still ""
with "tcp://localhost:4243".
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.
oh I also added:
req.Host = host
around like 92 in request.go
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.
oh yep, I think you're right @duglin it would be better to use NewClient
everywhere.
- renaming
newMockClient
tonewMockTransportClient
(ornewMockTransport
…) as it's more what it does. - probably creating a
newMockClient
that does callNewClient
, …
func newMockClient(tlsConfig *tls.Config, doer func(*http.Request) (*http.Response, error)) Client {
client, _ := NewClient(test.host, "", nil, nil)
client.transport = newMockTransport(tlsConfig, doer)
return client
}
I would even think we should check the error on NewClient
.
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.
@duglin, I think the main reason is that you added req.Host = host
in request.go, there is nothing to do with the NewClient
.
The req.Host
is initialized in http.NewRequest
before, and mostly it will be set to "" except the bug I mentioned above.
Now you manually added req.Host = host
, of course it will be equal to req.Host.URL
.
/cc @vdemeester
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.
Something feels wrong here. According to this test the HTTP Host
header will always be empty, which doesn't seem right to me. If it really is supposed to be blank then why include the string in the test data, just check for a static ""
in the if-statement. However, having an empty header is not correct and we should fix that.
I'll try to find some time to look at this but kind of busy today....
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.
@duglin Yeah, you are right. If it is supposed to be blank, we should just check it with a static ""
. There is indeed something wrong here, wait for your result. :)
@duglin @vdemeester Ping~ :P |
LGTM 🐶 |
if cli.proto == "unix" || cli.proto == "npipe" { | ||
// For local communications, it doesn't matter what the host is. We just | ||
// need a valid and meaningful host name. (See #189) | ||
host = "docker" |
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.
shouldn't this set req.Host
? We override the header (the thing that causes the problem on the server) only in the case that we need to talk to a Host that would cause a problem. The request still needs to go to the right place.
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.
@MHBauer Make sense to me, will update soon.
efcd30b
to
cb71c0a
Compare
@MHBauer Addressed comments. |
@Random-Liu thanks for the changes. I appreciate the comments as well. If I don't make sense call me on it. I think the three way tests were better. @vdemeester @duglin Am I on to something or misinterpreting? EDITED TO DELETE THE WRONG STUFF |
@MHBauer Unfortunately,
The reason is that the url we pass to |
Yea, I think that's an artifact of using the mock client. The request never actually gets to the The change feels correct to me, but I'm not sure the test is worthwhile if it doesn't connect to an actual server and go through the whole end to end integration scenario. |
Understanding it further, I would expect it to be:
|
LGTM for this as it is, based on my understanding. |
@MHBauer Addressed comments. |
Signed-off-by: Lantao Liu <[email protected]>
cb71c0a
to
d5a6705
Compare
I agree with @MHBauer about not using a real server for the testing. It feels like we're debugging/testing the testing code and not docker. Did anyone consider using a real http server in the tests like we do here: https://github.com/docker/docker/blob/master/integration-cli/docker_cli_config_test.go#L26 ? |
@duglin if the server part ended up in this repo it would be really easy to use as a test harness. We'd only need to provide test backends and we'd get end to end tests. This change LGTM. I'm going to merge it as it is, but we can keep the discussion going in an issue. |
Thank you for the contribution @Random-Liu! |
@MHBauer Thanks for your review and good suggestions. :) |
For issue #189.
In this PR, I set
URL.Host
to a fake address "docker.sock" to solve #189.Hope this could be in, thanks! :)
@duglin @vdemeester