Hi, Gabriel.  Thanks for the report.  Also, http-get doesn't support
TLS/SSL, and silently converts requests to HTTP.

I'm afraid that it's unlikely that this will be fixed soon.  In the
meantime, I offer you the code below, which I use to work around this
problem.  It calls curl in a subprocess.  Despite the extra overhead, it is
fast enough for most projects.

(define (curl-prepare-headers alist)
  (append-map (lambda (h)
                (list "--header"
                      (format #false "~A: ~A" (car h) (cdr h))))
              alist))

(define (curl-http-delete headers url)
  (call-with-output-string
   (lambda (port)
     (assert (zero?
              (run-synchronous-subprocess
               "/usr/bin/curl"
               (cons* "--request" "DELETE"
                      "--silent"
                      "--url" url
                      (curl-prepare-headers headers))
               'output port))
             "Error in HTTP DELETE."
             url))))

(define curl-http-get
  (case-lambda
   ((headers url)
    ;; This fails if a non-NFC string is returned.
    (call-with-output-string
     (lambda (port)
       (assert (zero?
                (run-synchronous-subprocess
                 "/usr/bin/curl"
                 (cons* "--location"
                        "--silent"
                        "--url" url
                        (curl-prepare-headers headers))
                 'output port))
               "Error in HTTP GET."
               url))))
   ((headers url pathname)
    (assert (zero?
             (run-synchronous-subprocess
              "/usr/bin/curl"
              (cons* "--location"
                     "--output" (enough-namestring pathname)
                     "--silent"
                     "--url" url
                     (curl-prepare-headers headers))))
            "Error in HTTP GET."
            url))))

(define (curl-http-put data headers url)
  (call-with-output-string
   (lambda (port)
     (assert (zero?
              (run-synchronous-subprocess
               "/usr/bin/curl"
               (cons* "--silent"
                      "--upload-file" "-"
                      "--url" url
                      (curl-prepare-headers headers))
               'input (open-input-string data)
               'output port))
             "Error in HTTP PUT."
             url))))

Reply via email to