Visitar URL original
Engine-api built with Go(<=1.4) won't work with Docker daemon built with Go(>=1.6) · Issue #189 · docker-archive-public/docker.engine-api · GitHub
Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Engine-api built with Go(<=1.4) won't work with Docker daemon built with Go(>=1.6) #189

Closed

Description

@Random-Liu

When using engine-api built with Go(<=1.4) with Docker daemon built with Go(>=1.6), it keeps complaining "Error response from daemon: 400 Bad Request: malformed Host header".

I think the reason is that:

  1. After golang/go@6e11f45, the http server in Go 1.6 will validate the HTTP Host header conforming to HTTP 1.1 (See net/http: HTTP/1.1 requests without Host header should be rejected  golang/go#13624)
  2. On the http client side, Go writes the HTTP Host header with request.Host or request.URL.Host(if the former is empty) (See here)
  3. When using the default docker endpoint (unix:///var/run/docker.sock), engine-api will set request.Host="", request.URL.Host="/var/run/docker.sock" (See set request.URL.Host and set request.Host)
  4. When the engine-api is built with Go >= 1.5, everything goes well, because Go will clean up the Host making both request.Host and request.URL.Host to "". Then the HTTP Host header will be "". (See net/http: does not verify validity of Host header golang/go#11206))
  5. But when the engine-api is built with Go<=1.4, Go won't clean up the Host, so the HTTP Host header will be "/var/run/docker.sock". It will break Go 1.6 http server side validation in 1. because '/'is not a valid character, causing 400 Bad Request: malformed Host header.

I could fix this by set some random but valid thing like "docker.sock" in the request.URL.Host. If it is not used for unix endpoint, why don't we just set it to a valid Host?

Hope this could be fixed, thanks! :)

More information kubernetes/kubernetes#23809

Activity

  1. duglin commented on Apr 4, 2016

    @duglin
    Contributor
  2. Random-Liu commented on Apr 4, 2016

    @Random-Liu
    ContributorAuthor

    @duglin Yeah, I saw that one. :)

    I think in moby/moby#20865, people were mainly talking about the Docker CLI. While this one is just talking about the engine-api, which is a little different:

    1. People may use engine-api to build anything, they may need to use Go 1.4 for some reason.
    2. This issue is easier to fix because it's only about engine-api, I don't think it will affect too many people.
  3. vdemeester commented on Apr 4, 2016

    @vdemeester
    Contributor

    I do agree with @Random-Liu, maybe we should handle this in here too.
    /cc @calavera @MHBauer

  4. Random-Liu commented on Apr 4, 2016

    @Random-Liu
    ContributorAuthor

    Thanks, @vdemeester!

    BTW, we are switching from go-dockerclient to this official engine-api, :). There is no such problem in go-dockerclient (See here)

  5. MHBauer commented on Apr 4, 2016

    @MHBauer
    Contributor

    We have control of the default client, so we should be able to handle it. Is there a way uses of engine-api can work around this by providing a customized client? We should work out both ways, if possible.

  6. duglin commented on Apr 4, 2016

    @duglin
    Contributor

    Explicitly setting the value to something meaningful and valid should be easy enough to do. A PR would be welcome....

  7. Random-Liu commented on Apr 4, 2016

    @Random-Liu
    ContributorAuthor

    @duglin Thanks, I'll send a PR soon :)

  8. calavera commented on Apr 21, 2016

    @calavera
    Contributor

    Fixed by #190.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions