Héllo again,

I'm trying hit the hackernews API hosted on firebase and I get an error when I try to use
streaming with guile 2.0.11

This works correctly:

```
(receive (response body) (https-get "https://hacker-news.firebaseio.com/v0/maxitem.json";)
  (pk (string->number (bytevector->string body "utf-8"))))
```

But the following, with #:streaming set to true doesn't work:

```
(receive (response body) (https-get "https://hacker-news.firebaseio.com/v0/maxitem.json"; #:streaming? #true)
  (pk (read-string body)))
```

Here is the backtrace:

```
In unknown file:
?: 4 [load-compiled/vm "/home/amirouche/.cache/guile/ccache/2.0-LE-8-2.0/home/amirouche/src/guile/hyper/src/buggy-https-get.scm.go"]
In /home/amirouche/src/guile/hyper/src/buggy-https-get.scm:
  90: 3 [#<procedure 1a33420 ()>]
In ice-9/rdelim.scm:
 159: 2 [read-string #<input: r6rs-custom-binary-input-port 1aaa680> #f]
143: 1 [read-string! "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ...]
In unknown file:
   ?: 0 [read-char #<input: r6rs-custom-binary-input-port 1aaa680>]

ERROR: In procedure read-char:
ERROR: Throw to key `bad-response' with args `("EOF while reading response body: ~a bytes of ~a" (0 8))'.
```

I attached an example script to this mail.

Thanks in advance!

--
Amirouche ~ amz3 ~ http://www.hyperdev.fr
;;; (https-get)

;; Copyright (C) 2013, 2014 Aleix Conchillo Flaque <aconchi...@gmail.com>
;; Copyright (C) 2016 Amirouche Boubekki <amirou...@hypermove.net>
;;
;; This file is based on guile-oauth's (oauth oauth1 utils).
;;
;; https-get is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 3 of the License, or (at your option) any later version.
;;
;; https-get is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with guile-oauth; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301 USA

;;; Commentary:

;; https-get for Guile

;;; Code:

(define-module (https-get)
  #:use-module (gnutls)
  #:use-module (ice-9 binary-ports)
  #:use-module (ice-9 receive)
  #:use-module (ice-9 match)
  #:use-module (rnrs bytevectors)
  #:use-module (srfi srfi-19)
  #:use-module (web client)
  #:use-module (web uri)
  #:export (https-get
            http-get*))

;;
;; HTTP/HTTPS methods
;;

(define (https-call https-proc)
  (lambda* (uri #:key (headers '()) (streaming? #f))
    (let* ((socket (open-socket-for-uri uri))
           (session (make-session connection-end/client)))
      ;; (set-log-level! 9)
      ;; (set-log-procedure!
      ;;  (lambda (level msg) (format #t "|<~d>| ~a" level msg)))

      ;; Use the file descriptor that underlies SOCKET.
      (set-session-transport-fd! session (fileno socket))

      ;; Use the default settings.
      (set-session-priorities! session "NORMAL")

      ;; Create anonymous credentials.
      (set-session-credentials! session
                                (make-anonymous-client-credentials))
      (set-session-credentials! session
                                (make-certificate-credentials))

      ;; Perform the TLS handshake with the server.
      (handshake session)

      (receive (response body)
          (https-proc uri
                     #:port (session-record-port session)
                     #:keep-alive? #t
                     #:headers headers
                     #:streaming? streaming?)
        (bye session close-request/rdwr)
        (values response body)))))

(define https-get (https-call http-get))

(use-modules (web response))
(use-modules (ice-9 receive))
(use-modules (ice-9 rdelim))
(use-modules (ice-9 iconv))


(receive (response body) (https-get 
"https://hacker-news.firebaseio.com/v0/maxitem.json";)
  (pk (string->number (bytevector->string body "utf-8"))))


(receive (response body) (https-get 
"https://hacker-news.firebaseio.com/v0/maxitem.json"; #:streaming? #true)
  (pk (read-string body)))

Reply via email to