[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using UNIX sockets (Zelphir Kaltstahl)

From: Zelphir Kaltstahl
Subject: Re: Using UNIX sockets (Zelphir Kaltstahl)
Date: Sun, 2 Jun 2019 16:03:47 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

Hi Guile Users!

I think I've made some progress on how to communicate with dockerd over
its UNIX socket. This is what I have now:

(use-modules (web client)
             (ice-9 iconv))

(define* (connect-to-docker-socket #:key (socket-path "/var/run/docker.sock"))
  (let ([docker-sock-addr (make-socket-address AF_UNIX socket-path)]
        [docker-sock (socket PF_UNIX SOCK_STREAM 0)])
    ;; socket options:
    (setsockopt docker-sock SOL_SOCKET SO_REUSEADDR 1)
    ;; usage of connect:
    ;; server side would use `bind`, `accept` and `listen`.
    ;; client side uses `connect` and `close`.
    (connect docker-sock docker-sock-addr)

(let ([sock (connect-to-docker-socket)])
      (lambda ()
        (http-get "unix:/var/run/docker.sock/containers/json?all=true"
                  #:port sock
                  ;; dockerd uses HTTP 1.1 it seems.
                  ;; other values will result in: "Bad Request: unsupported 
protocol version"
                  #:version '(1 . 1)
                  #:keep-alive? #f
                  ;; Apparently the `host` header must be specified.
                  ;; The `host` header in this case is ???.
                  #:headers '((host . "localhost"))
                  #:decode-body? #t
                  #:streaming? #f))
    (lambda (response response-text)
      (display response)
      (display response-text)))
  (close sock))

So I am trying to use `web client` to send HTTP requests to the socket
and I thing that the socket is now created correctly (although I am not
sure about it).

Now I get the following error:

web/request.scm:184:10: In procedure build-request:
Bad request: Bad value for header host: "localhost"

However, according to:
any string should be fine as host, host header only being a required
header for HTTP 1.1 requests. I am now unsure how to progress from here.
What will be accepted as a not bad value for the host header instead? I
also tried to use empty string and string of one space and such things,
all with the same result. Initially it was also not clear how to write
the symbol for host header, 'HOST, 'Host or 'host, but that seems to be
figured out now.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]