mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 13:49:17 +02:00
Adding call-with-input-url/headers convenience utility.
This commit is contained in:
parent
7727c4c45d
commit
f85c7ffa6f
2 changed files with 15 additions and 4 deletions
|
@ -100,9 +100,9 @@
|
|||
(let ((enc (assq-ref headers 'transfer-encoding)))
|
||||
(cond
|
||||
((equal? enc "chunked")
|
||||
(http-wrap-chunked-input-port in))
|
||||
(cons headers (http-wrap-chunked-input-port in)))
|
||||
(else
|
||||
in))))
|
||||
(cons headers in)))))
|
||||
((3)
|
||||
(close-input-port in)
|
||||
(close-output-port out)
|
||||
|
@ -115,17 +115,26 @@
|
|||
(close-output-port out)
|
||||
(error "couldn't retrieve url" url resp)))))))))
|
||||
|
||||
(define (http-get url . headers)
|
||||
(define (http-get/headers url . headers)
|
||||
(http-get/raw url
|
||||
(if (pair? headers) (car headers) '())
|
||||
http-redirect-limit))
|
||||
|
||||
(define (http-get url . headers)
|
||||
(cdr (apply http-get/headers url headers)))
|
||||
|
||||
(define (call-with-input-url url proc)
|
||||
(let* ((p (http-get url))
|
||||
(res (proc p)))
|
||||
(close-input-port p)
|
||||
res))
|
||||
|
||||
(define (call-with-input-url/headers url proc)
|
||||
(let* ((h+p (http-get/headers url))
|
||||
(res (proc (car h+p) (cdr h+p))))
|
||||
(close-input-port (cdr h+p))
|
||||
res))
|
||||
|
||||
(define (with-input-from-url url thunk)
|
||||
(let ((p (http-get url)))
|
||||
(let ((res (parameterize ((current-input-port p)) (thunk))))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
(define-library (chibi net http)
|
||||
(export http-get call-with-input-url with-input-from-url
|
||||
(export http-get http-get/headers
|
||||
call-with-input-url call-with-input-url/headers
|
||||
with-input-from-url
|
||||
http-parse-request http-parse-form)
|
||||
(import (chibi) (srfi 39) (chibi net) (chibi io)
|
||||
(chibi uri) (chibi mime))
|
||||
|
|
Loading…
Add table
Reference in a new issue