From patchwork Fri May 21 08:32:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Othacehe X-Patchwork-Id: 29449 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id A287627BC81; Fri, 21 May 2021 09:45:47 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 705BC27BC78 for ; Fri, 21 May 2021 09:45:47 +0100 (BST) Received: from localhost ([::1]:35330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lk0mw-0002Zy-N2 for patchwork@mira.cbaines.net; Fri, 21 May 2021 04:45:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lk0ac-0007uo-EU for guix-patches@gnu.org; Fri, 21 May 2021 04:33:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52478) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lk0ac-0008LL-7R for guix-patches@gnu.org; Fri, 21 May 2021 04:33:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lk0ac-0006Du-4x for guix-patches@gnu.org; Fri, 21 May 2021 04:33:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48556] [PATCH 2/4] scripts: publish: Forward the request connection header. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 21 May 2021 08:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48556 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48556@debbugs.gnu.org Cc: Mathieu Othacehe Received: via spool by 48556-submit@debbugs.gnu.org id=B48556.162158595323858 (code B ref 48556); Fri, 21 May 2021 08:33:02 +0000 Received: (at 48556) by debbugs.gnu.org; 21 May 2021 08:32:33 +0000 Received: from localhost ([127.0.0.1]:35785 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lk0a9-0006Ce-2M for submit@debbugs.gnu.org; Fri, 21 May 2021 04:32:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33756) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lk0a7-0006C9-BC for 48556@debbugs.gnu.org; Fri, 21 May 2021 04:32:31 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36242) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lk0a2-0007yU-5H for 48556@debbugs.gnu.org; Fri, 21 May 2021 04:32:26 -0400 Received: from [2a01:e0a:19b:d9a0:f2f7:a404:c3d3:f8b4] (port=37202 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lk0a1-0004xH-MQ; Fri, 21 May 2021 04:32:25 -0400 From: Mathieu Othacehe Date: Fri, 21 May 2021 10:32:17 +0200 Message-Id: <20210521083219.20714-2-othacehe@gnu.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210521083219.20714-1-othacehe@gnu.org> References: <20210521083219.20714-1-othacehe@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches The Guile web server is reading the response connection header to decide whether to close the connection. However, as the request connection header is not forwarded to the response, this mechanism cannot work. * guix/scripts/publish.scm (add-extra-headers): New procedure. (make-request-handler): Use it to forward the request connection header to the response. --- guix/scripts/publish.scm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index 19fed574c2..260f98edf0 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -34,6 +34,7 @@ #:use-module (srfi srfi-2) #:use-module (srfi srfi-9) #:use-module (srfi srfi-9 gnu) + #:use-module (srfi srfi-11) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) @@ -1034,6 +1035,14 @@ methods, return the applicable compression." compressions) (default-compression requested-type))) +(define (add-extra-headers request response) + "Append the REQUEST connection header to the given RESPONSE headers and +return them." + (if (pair? response) + `(,@response + ,(assq 'connection (request-headers request))) + response)) + (define* (make-request-handler store #:key cache pool @@ -1047,7 +1056,7 @@ methods, return the applicable compression." (let ((expected (split-and-decode-uri-path nar-path))) (cut equal? expected <>))) - (lambda (request body) + (define (handle request body) (format #t "~a ~a~%" (request-method request) (uri-path (request-uri request))) @@ -1119,7 +1128,15 @@ methods, return the applicable compression." (not-found request))) (x (not-found request))) - (not-found request)))) + (not-found request))) + + ;; Forward the request connection header to the response, so that the server + ;; can close the connection if this is requested by the client. + (lambda (request body) + (let-values (((response response-body) + (handle request body))) + (values (add-extra-headers request response) + response-body)))) (define (service-name) "Return the Avahi service name of the server."