Docker Community Forums

Share and learn in the Docker community.

Daemon Remote API Not responding to HTTP/1.1 (but does for HTTP/1.0)

I’m attempting to retrieve stats of the containers on my host, however I’ve noticed that I cannot use HTTP/1.1 as part of the request. Experimenting, HTTP/1.0 does work, contrary to the examples here: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/

To reproduce not working:

user@docker-host:~/dockerwatcher$ socat - UNIX-CONNECT:/var/run/docker.sock
GET /info HTTP/1.1

HTTP/1.1 400 Bad Request
Content-Type: text/plain
Connection: close

400 Bad Request: missing required Host header

To produce working:

user@docker-host:~/dockerwatcher$ socat - UNIX-CONNECT:/var/run/docker.sock
GET /info HTTP/1.0

HTTP/1.0 200 OK
Content-Type: application/json
Server: Docker/1.12.5 (linux)
Date: Wed, 04 Jan 2017 21:56:42 GMT

{"ID":<snip>}

I went hunting around to see about required host headers to no avail.

OS: Ubuntu 16.04.1 LTS
Docker 1.12.5
It also occurs on Docker For Mac version 1.13-r3 with API version 1.25.

Is this expected behavior or am I executing things improperly?

RFC 7230 §5.4 states that HTTP 1.1 messages MUST contain a Host: header. (And, correspondingly, that servers MUST respond 400 Bad Request if it’s absent, which the Docker daemon does.)

Ahh, good to know that the API attempts to fully follow the HTTP implementation. I cannot find in the docs where it states that, only that it “tends to be REST” and uses HTTP response codes. I’ll adjust all of my calls to be fully HTTP compliant.

Thanks.