[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#53818] [PATCH v3 2/7] http-client: Make 'http-fetch/cached' take '#
From: |
Xinglu Chen |
Subject: |
[bug#53818] [PATCH v3 2/7] http-client: Make 'http-fetch/cached' take '#:headers' argument. |
Date: |
Wed, 09 Feb 2022 14:24:25 +0100 |
* guix/http-client.scm (http-fetch/cached): Take ‘#:headers’ keyword argument.
---
guix/http-client.scm | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/guix/http-client.scm b/guix/http-client.scm
index 10bc278023..058f09852f 100644
--- a/guix/http-client.scm
+++ b/guix/http-client.scm
@@ -3,6 +3,7 @@
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2012, 2015 Free Software Foundation, Inc.
;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2022 Xinglu Chen <public@yoctocell.xyz>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -283,9 +284,11 @@ (define* (http-fetch/cached uri #:key (ttl
(%http-cache-ttl)) text?
(write-cache dump-port)
(cache-miss (const #t))
(log-port (current-error-port))
- (timeout 10))
+ (timeout 10)
+ (headers '((user-agent . "GNU Guile"))))
"Like 'http-fetch', return an input port, but cache its contents in
-~/.cache/guix. The cache remains valid for TTL seconds.
+~/.cache/guix. The cache remains valid for TTL seconds. HEADERS is an alist
+of extra HTTP headers. The cache time will automatically be added to HEADERS,
so there is no need to specify it.
Call WRITE-CACHE with the HTTP input port and the cache output port to write
the data to cache. Call CACHE-MISS with URI just before fetching data from
@@ -300,8 +303,8 @@ (define cache-time
(and cache-port
(stat:mtime (stat cache-port))))
- (define headers
- `((user-agent . "GNU Guile")
+ (define headers*
+ `(,@headers
,@(if cache-time
`((if-modified-since
. ,(time-utc->date (make-time time-utc 0 cache-time))))
@@ -316,7 +319,7 @@ (define headers
(raise c))))
(let ((port (http-fetch uri #:text? text?
#:log-port log-port
- #:headers headers #:timeout timeout)))
+ #:headers headers* #:timeout timeout)))
(cache-miss uri)
(mkdir-p (dirname file))
(when cache-port
--
2.34.1
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., (continued)
[bug#53818] [PATCH v2 3/7] http-client: 'http-fetch/cached' accepts a string or a <uri>., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 2/7] http-client: Make 'http-fetch/cached' take '#:headers' argument., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 6/7] gnu: xorg-server-xwayland: Set 'repology-name' property., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 7/7] gnu: xorg-server-xwayland: Prepare for cross-compilation., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 4/7] import: json: Make 'json-fetch' take '#:cached?' argument., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v3 0/7] Add Repology updater, Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 2/7] http-client: Make 'http-fetch/cached' take '#:headers' argument.,
Xinglu Chen <=
- [bug#53818] [PATCH v3 3/7] http-client: 'http-fetch/cached' accepts a string or a <uri>., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 1/7] upstream: Sort list of updaters., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 4/7] import: json: Make 'json-fetch' take '#:http-fetch' argument., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 7/7] gnu: xorg-server-xwayland: Prepare for cross-compilation., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 6/7] gnu: xorg-server-xwayland: Set 'repology-name' property., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 5/7] import: Add 'repology' updater., Xinglu Chen, 2022/02/09
[bug#53818] [PATCH 0/3] Add Repology updater, Ludovic Courtès, 2022/02/08