diff --git a/lib/chibi/net/http.scm b/lib/chibi/net/http.scm index a84b5f87..4a259d84 100644 --- a/lib/chibi/net/http.scm +++ b/lib/chibi/net/http.scm @@ -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)))) diff --git a/lib/chibi/net/http.sld b/lib/chibi/net/http.sld index 0a33febe..796d9448 100644 --- a/lib/chibi/net/http.sld +++ b/lib/chibi/net/http.sld @@ -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))