From patchwork Fri May 21 08:27:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Othacehe X-Patchwork-Id: 29443 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 C0C6127BC81; Fri, 21 May 2021 09:28:21 +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 9126B27BC78 for ; Fri, 21 May 2021 09:28:21 +0100 (BST) Received: from localhost ([::1]:58300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lk0W4-0006Ln-PD for patchwork@mira.cbaines.net; Fri, 21 May 2021 04:28:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lk0Vo-0005xW-4S for guix-patches@gnu.org; Fri, 21 May 2021 04:28:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lk0Vn-0005PD-T5 for guix-patches@gnu.org; Fri, 21 May 2021 04:28:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lk0Vn-00062j-QQ for guix-patches@gnu.org; Fri, 21 May 2021 04:28:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48559] [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:28:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48559 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48559@debbugs.gnu.org Cc: Mathieu Othacehe X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162158565223157 (code B ref -1); Fri, 21 May 2021 08:28:03 +0000 Received: (at submit) by debbugs.gnu.org; 21 May 2021 08:27:32 +0000 Received: from localhost ([127.0.0.1]:35742 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lk0VI-00061L-9v for submit@debbugs.gnu.org; Fri, 21 May 2021 04:27:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:44360) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lk0VF-00060y-Uo for submit@debbugs.gnu.org; Fri, 21 May 2021 04:27:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lk0VF-0005J9-KJ for guix-patches@gnu.org; Fri, 21 May 2021 04:27:29 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36136) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lk0VB-00053S-V9 for guix-patches@gnu.org; Fri, 21 May 2021 04:27:27 -0400 Received: from [2a01:e0a:19b:d9a0:f2f7:a404:c3d3:f8b4] (port=37126 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 1lk0V7-0003nM-Vj; Fri, 21 May 2021 04:27:25 -0400 From: Mathieu Othacehe Date: Fri, 21 May 2021 10:27:11 +0200 Message-Id: <20210521082713.20169-2-othacehe@gnu.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210521082713.20169-1-othacehe@gnu.org> References: <20210521082713.20169-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."