From 2de227af4bca7204e93f48d52555d576c25f1ca9 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 10 Feb 2014 00:03:34 +0100 Subject: download: Provide a 'User-Agent' field in HTTP requests. Fixes . Reported by Raimon Grau . * guix/build/download.scm (http-fetch)[headers]: New variable. Pass it as #:headers or #:extra-headers to 'http-get' and 'http-get*'. --- guix/build/download.scm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'guix/build') diff --git a/guix/build/download.scm b/guix/build/download.scm index ac2086d96e..f9715e10f7 100644 --- a/guix/build/download.scm +++ b/guix/build/download.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -201,6 +201,12 @@ (define post-2.0.7? (string>? (micro-version) "7") (string>? (version) "2.0.7"))) + (define headers + ;; Some web sites, such as http://dist.schmorp.de, would block you if + ;; there's no 'User-Agent' header, presumably on the assumption that + ;; you're a spammer. So work around that. + '((User-Agent . "GNU Guile"))) + (let*-values (((connection) (open-connection-for-uri uri)) ((resp bv-or-port) @@ -210,11 +216,14 @@ (define post-2.0.7? ;; version. So keep this compatibility hack for now. (if post-2.0.7? (http-get uri #:port connection #:decode-body? #f - #:streaming? #t) + #:streaming? #t + #:headers headers) (if (module-defined? (resolve-interface '(web client)) 'http-get*) - (http-get* uri #:port connection #:decode-body? #f) - (http-get uri #:port connection #:decode-body? #f)))) + (http-get* uri #:port connection #:decode-body? #f + #:headers headers) + (http-get uri #:port connection #:decode-body? #f + #:extra-headers headers)))) ((code) (response-code resp)) ((size) -- cgit v1.2.3