@@ -82,7 +82,8 @@ (define* (http-fetch uri #:key port (text? #f) (buffered? #t)
(verify-certificate? #t)
(headers '((user-agent . "GNU Guile")))
(log-port (current-error-port))
- timeout)
+ timeout
+ (accept-all-response-codes? #f))
"Return an input port containing the data at URI, and the expected number of
bytes available or #f. If TEXT? is true, the data at URI is considered to be
textual. Follow any HTTP redirection. When BUFFERED? is #f, return an
@@ -99,7 +100,9 @@ (define* (http-fetch uri #:key port (text? #f) (buffered? #t)
Write information about redirects to LOG-PORT.
-Raise an '&http-get-error' condition if downloading fails."
+When ACCEPT-ALL-RESPONSE-CODES? is false then raise an '&http-get-error'
+condition if downloading fails, otherwise return the response regardless
+of the reponse code."
(define parsed-initial-uri
(if (string? uri) (string->uri uri) uri))
@@ -150,7 +153,9 @@ (define (open-connection* uri)
current-port)
(open-connection* new-uri)))))
(else
- (raise (condition (&http-get-error
+ (if accept-all-response-codes?
+ (values data (response-content-length resp))
+ (raise (condition (&http-get-error
(uri current-uri)
(code code)
(reason (response-reason-phrase resp))
@@ -161,7 +166,7 @@ (define (open-connection* uri)
#f
(G_ "~a: HTTP download failed: ~a (~s)")
(uri->string current-uri) code
- (response-reason-phrase resp))))))))))))
+ (response-reason-phrase resp)))))))))))))
(define-syntax-rule (false-if-networking-error exp)
"Return #f if EXP triggers a network related exception as can occur when