From 6d459a442d73628a0628385283c7cf04dff1b797 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Tue, 21 Mar 2017 15:31:56 +0100 Subject: [PATCH] http-client: Warn on proxy cache misses. Still not a good idea. * guix/http-client.scm (http-fetch): Add #:peek-behind-proxy parameter to expose caching proxy implementation details as a scary warning. * guix/scripts/substitute.scm (fetch): Use it. --- guix/http-client.scm | 10 +++++++++- guix/scripts/substitute.scm | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index 6874c51..2366f5e 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès ;;; Copyright © 2015 Mark H Weaver ;;; Copyright © 2012, 2015 Free Software Foundation, Inc. +;;; Copyright © 2017 Tobias Geerinckx-Rice ;;; ;;; This file is part of GNU Guix. ;;; @@ -222,7 +223,8 @@ or if EOF is reached." (define* (http-fetch uri #:key port (text? #f) (buffered? #t) keep-alive? (verify-certificate? #t) - (headers '((user-agent . "GNU Guile")))) + (headers '((user-agent . "GNU Guile"))) + (peek-behind-cache? #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 @@ -253,8 +255,14 @@ Raise an '&http-get-error' condition if downloading fails." (http-get uri #:streaming? #t #:port port #:keep-alive? #t #:headers headers)) + ((headers) + (response-headers resp)) ((code) (response-code resp))) + (when (and peek-behind-cache? + (equal? (assoc-ref headers 'x-cache-status) "MISS")) + (warning (_ "the caching proxy is working properly!~%")) + (warning (_ "and there's nothing you can do about it.~%"))) (case code ((200) (values data (response-content-length resp))) diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index faeb019..4a4f115 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -216,7 +216,8 @@ provide." (unless (or buffered? (not (file-port? port))) (setvbuf port _IONBF))) (http-fetch uri #:text? #f #:port port - #:verify-certificate? #f)))))) + #:verify-certificate? #f + #:peek-behind-cache? #t)))))) (else (leave (_ "unsupported substitute URI scheme: ~a~%") (uri->string uri))))) -- 2.9.3