unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@gmail.com>
To: guile-user@gnu.org
Subject: Re: Using UNIX sockets (Zelphir Kaltstahl)
Date: Sun, 2 Jun 2019 16:01:53 +0200	[thread overview]
Message-ID: <eb47241d-f234-6547-8fdb-a75bb54b5832@gmail.com> (raw)
In-Reply-To: <mailman.105.1559404818.12235.guile-user@gnu.org>

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:
    ;; https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html
    (setsockopt docker-sock SOL_SOCKET SO_REUSEADDR 1)
    ;; usage of connect:
    ;; https://www.gnu.org/software/guile/manual/html_node/Network-Sockets-and-Communication.html#Network-Sockets-and-Communication
    ;; server side would use `bind`, `accept` and `listen`.
    ;; client side uses `connect` and `close`.
    (connect docker-sock docker-sock-addr)
    docker-sock))


(let ([sock (connect-to-docker-socket)])
  (call-with-values
      (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: https://github.com/request/request/issues/2327
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.

Regards,

Zelphir



       reply	other threads:[~2019-06-02 14:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.105.1559404818.12235.guile-user@gnu.org>
2019-06-02 14:01 ` Zelphir Kaltstahl [this message]
2019-06-02 16:29   ` Using UNIX sockets (Zelphir Kaltstahl) Ludovic Courtès
2019-06-02 14:03 ` Zelphir Kaltstahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb47241d-f234-6547-8fdb-a75bb54b5832@gmail.com \
    --to=zelphirkaltstahl@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).