ConfigureTransport: enable compression for non unix/npipe protos #106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ConfigureTransport
is used by the official Docker client to set up itshttp.Transport
:NewClientWithOpts()
starts by callingdefaultHTTPClient()
which creates a newhttp.Transport
and callConfigureTransport
with either the default unix socket address, or the default npipe socket address (see here). This first call toConfigureTransport
will setDisableCompression
to false.WithHost()
is called,ConfigureTransport
is called once again with the samehttp.Transport
instance. If that hostURL uses tcp proto, we fall inConfigureTransport
's default switch case, which doesn't resetDisableCompression
. This effectively means that the Docker client has (presumably) never been using HTTP compression for TCP hosts.Note that
WithHost
is called whenever theWithHostFromEnv
orFromEnv
option funcs are used.We think it does make sense to keep compression disabled for unix / npipe sockets (it would just make the CPU needlessly spin more if we enable it), and we think it generally also makes sense to enable it for HTTP over TCP.
We discussed creating a new
http.Transport
in Docker client codebase wheneverConfigureTransport
is called, but we can't do that without introducing major side-effects (see here). So we still have to leave in a world where multiple calls toConfigureTransport
might be made for the samehttp.Transport
.As such, this commit make sure compression is enabled for non unix / npipe protos.
If
ConfigureTransport
callers really want to make sure compression is disabled, they should setDisableCompression
only after all subsequent calls toConfigureTransport
have been made. The comment on that function has also been updated to reflect that.For the record,
DisableCompression = true
was first introduced in this repo by 88d5fb2, which can be tracked down to this initial change in moby/moby: moby/moby@fb7ceeb