From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: [PATCH] http-client: Support basic authentication. Date: Wed, 16 Dec 2015 13:28:46 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9BCX-0000ps-TH for guix-devel@gnu.org; Wed, 16 Dec 2015 07:29:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9BCS-0007yR-NC for guix-devel@gnu.org; Wed, 16 Dec 2015 07:29:01 -0500 Received: from sinope.bbbm.mdc-berlin.de ([141.80.25.23]:36668) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9BCS-0007yB-AZ for guix-devel@gnu.org; Wed, 16 Dec 2015 07:28:56 -0500 Received: from localhost (localhost [127.0.0.1]) by sinope.bbbm.mdc-berlin.de (Postfix) with ESMTP id DB9B02808DE for ; Wed, 16 Dec 2015 13:28:53 +0100 (CET) Received: from sinope.bbbm.mdc-berlin.de ([127.0.0.1]) by localhost (sinope.bbbm.mdc-berlin.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KXxj2kvroEy5 for ; Wed, 16 Dec 2015 13:28:47 +0100 (CET) Received: from HTCAONE.mdc-berlin.net (mab.citx.mdc-berlin.de [141.80.36.102]) by sinope.bbbm.mdc-berlin.de (Postfix) with ESMTP for ; Wed, 16 Dec 2015 13:28:47 +0100 (CET) In-Reply-To: List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: "guix-devel@gnu.org" --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The attached patch is better. Turns out I really didn=E2=80=99t understa= nd =E2=80=98let*-values=E2=80=99, so it=E2=80=99s better to do this in the o= uter =E2=80=98let=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename="0001-http-client-Support-basic-authentication.patch" >From 056ca0bfb03e14c698ffd984c36bb396d5aed492 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Wed, 16 Dec 2015 11:12:46 +0100 Subject: [PATCH] http-client: Support basic authentication. * guix/http-client.scm (http-fetch): Add Authorization header to request when the URI contains userinfo. --- guix/http-client.scm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index eb2c3f4..c7cbc82 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -32,6 +32,7 @@ #:use-module (rnrs bytevectors) #:use-module (guix ui) #:use-module (guix utils) + #:use-module (guix base64) #:use-module ((guix build utils) #:select (mkdir-p dump-port)) #:use-module ((guix build download) @@ -210,15 +211,23 @@ Raise an '&http-get-error' condition if downloading fails." (let loop ((uri (if (string? uri) (string->uri uri) uri))) - (let ((port (or port (open-connection-for-uri uri)))) + (let ((port (or port (open-connection-for-uri uri))) + (auth-header (match (uri-userinfo uri) + ((? string? str) + (list (cons 'Authorization + (string-append "Basic " + (base64-encode + (string->utf8 str)))))) + (_ '())))) (unless buffered? (setvbuf port _IONBF)) (let*-values (((resp data) ;; Try hard to use the API du jour to get an input port. (if (guile-version>? "2.0.7") - (http-get uri #:streaming? #t #:port port) ; 2.0.9+ + (http-get uri #:streaming? #t #:port port + #:headers auth-header) ; 2.0.9+ (http-get* uri #:decode-body? text? ; 2.0.7 - #:port port))) + #:port port #:headers auth-header))) ((code) (response-code resp))) (case code -- 2.1.0 --=-=-=--