File guix/http-client.scm changed (mode: 100644) (index 5a5a33b4c0..a767175d67) |
71 |
71 |
|
|
72 |
72 |
(define* (http-fetch uri #:key port (text? #f) (buffered? #t) |
(define* (http-fetch uri #:key port (text? #f) (buffered? #t) |
73 |
73 |
(verify-certificate? #t) |
(verify-certificate? #t) |
74 |
|
(headers '((user-agent . "GNU Guile")))) |
|
|
74 |
|
(headers '((user-agent . "GNU Guile"))) |
|
75 |
|
timeout) |
75 |
76 |
"Return an input port containing the data at URI, and the expected number of |
"Return an input port containing the data at URI, and the expected number of |
76 |
77 |
bytes available or #f. If TEXT? is true, the data at URI is considered to be |
bytes available or #f. If TEXT? is true, the data at URI is considered to be |
77 |
78 |
textual. Follow any HTTP redirection. When BUFFERED? is #f, return an |
textual. Follow any HTTP redirection. When BUFFERED? is #f, return an |
|
... |
... |
extra HTTP headers. |
80 |
81 |
|
|
81 |
82 |
When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates. |
When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates. |
82 |
83 |
|
|
|
84 |
|
TIMEOUT specifies the timeout in seconds for connection establishment; when |
|
85 |
|
TIMEOUT is #f, connection establishment never times out. |
|
86 |
|
|
83 |
87 |
Raise an '&http-get-error' condition if downloading fails." |
Raise an '&http-get-error' condition if downloading fails." |
84 |
88 |
(let loop ((uri (if (string? uri) |
(let loop ((uri (if (string? uri) |
85 |
89 |
(string->uri uri) |
(string->uri uri) |
86 |
90 |
uri))) |
uri))) |
87 |
91 |
(let ((port (or port (guix:open-connection-for-uri uri |
(let ((port (or port (guix:open-connection-for-uri uri |
88 |
92 |
#:verify-certificate? |
#:verify-certificate? |
89 |
|
verify-certificate?))) |
|
|
93 |
|
verify-certificate? |
|
94 |
|
#:timeout timeout))) |
90 |
95 |
(headers (match (uri-userinfo uri) |
(headers (match (uri-userinfo uri) |
91 |
96 |
((? string? str) |
((? string? str) |
92 |
97 |
(cons (cons 'Authorization |
(cons (cons 'Authorization |
|
... |
... |
Raise an '&http-get-error' condition if downloading fails." |
155 |
160 |
|
|
156 |
161 |
(define* (http-fetch/cached uri #:key (ttl (%http-cache-ttl)) text? |
(define* (http-fetch/cached uri #:key (ttl (%http-cache-ttl)) text? |
157 |
162 |
(write-cache dump-port) |
(write-cache dump-port) |
158 |
|
(cache-miss (const #t))) |
|
|
163 |
|
(cache-miss (const #t)) |
|
164 |
|
(timeout 10)) |
159 |
165 |
"Like 'http-fetch', return an input port, but cache its contents in |
"Like 'http-fetch', return an input port, but cache its contents in |
160 |
166 |
~/.cache/guix. The cache remains valid for TTL seconds. |
~/.cache/guix. The cache remains valid for TTL seconds. |
161 |
167 |
|
|
162 |
168 |
Call WRITE-CACHE with the HTTP input port and the cache output port to write |
Call WRITE-CACHE with the HTTP input port and the cache output port to write |
163 |
169 |
the data to cache. Call CACHE-MISS with URI just before fetching data from |
the data to cache. Call CACHE-MISS with URI just before fetching data from |
164 |
|
URI." |
|
|
170 |
|
URI. |
|
171 |
|
|
|
172 |
|
TIMEOUT specifies the timeout in seconds for connection establishment." |
165 |
173 |
(let ((file (cache-file-for-uri uri))) |
(let ((file (cache-file-for-uri uri))) |
166 |
174 |
(define (update-cache cache-port) |
(define (update-cache cache-port) |
167 |
175 |
(define cache-time |
(define cache-time |
|
... |
... |
URI." |
183 |
191 |
cache-port) |
cache-port) |
184 |
192 |
(raise c)))) |
(raise c)))) |
185 |
193 |
(let ((port (http-fetch uri #:text? text? |
(let ((port (http-fetch uri #:text? text? |
186 |
|
#:headers headers))) |
|
|
194 |
|
#:headers headers #:timeout timeout))) |
187 |
195 |
(cache-miss uri) |
(cache-miss uri) |
188 |
196 |
(mkdir-p (dirname file)) |
(mkdir-p (dirname file)) |
189 |
197 |
(when cache-port |
(when cache-port |