From patchwork Mon Sep 19 12:52:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Hesse X-Patchwork-Id: 2082 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [2a01:4f9:c010:3052::1] by patchwork.archlinux.org with IMAP (fetchmail-6.4.33) for (single-drop); Mon, 19 Sep 2022 12:53:14 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id BQDhBjpmKGPpFwMAK+/4rw (envelope-from ) for ; Mon, 19 Sep 2022 12:53:14 +0000 Received: from lists.archlinux.org (lists.archlinux.org [IPv6:2a01:4f9:c010:9eb4::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id 9E7BD149C0C6; Mon, 19 Sep 2022 12:53:12 +0000 (UTC) Received: from lists.archlinux.org (localhost [127.0.0.1]) by lists.archlinux.org (Postfix) with ESMTP id 50C4A433052; Mon, 19 Sep 2022 12:53:10 +0000 (UTC) Received: from mx.mylinuxtime.de (mx.mylinuxtime.de [195.201.174.144]) by lists.archlinux.org (Postfix) with ESMTPS id 21287433047 for ; Mon, 19 Sep 2022 12:53:06 +0000 (UTC) Received: from leda.eworm.de (unknown [194.36.25.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx.mylinuxtime.de (Postfix) with ESMTPSA id 8F7A81F2263; Mon, 19 Sep 2022 14:53:05 +0200 (CEST) Received: by leda.eworm.de (Postfix, from userid 1000) id 1F34118714C; Mon, 19 Sep 2022 14:53:05 +0200 (CEST) From: Christian Hesse To: Discussion list for pacman development Subject: [PATCH 1/1] support http header 'Cache-Control: no-cache' for soft failure Date: Mon, 19 Sep 2022 14:52:10 +0200 Message-Id: <20220919125210.63357-1-list@eworm.de> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Message-ID-Hash: DPGER63BTQD6M2DOXRZRBWCC4Z4HJ3QE X-Message-ID-Hash: DPGER63BTQD6M2DOXRZRBWCC4Z4HJ3QE X-MailFrom: eworm@leda.eworm.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Christian Hesse X-Mailman-Version: 3.3.5 Precedence: list List-Id: Discussion list for pacman development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Authentication-Results: mail.archlinux.org; dkim=none; dmarc=none; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 2a01:4f9:c010:9eb4::1 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org X-Rspamd-Queue-Id: 9E7BD149C0C6 X-Spamd-Result: default: False [0.79 / 15.00]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; RCVD_IN_DNSWL_MED(-0.20)[2a01:4f9:c010:9eb4::1:from]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f9:c010:9eb4::1]; MAILLIST(-0.20)[mailman]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; NEURAL_HAM(-0.00)[-1.000]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; ASN(0.00)[asn:24940, ipnet:2a01:4f9::/32, country:DE]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_ALL(0.00)[]; DMARC_NA(0.00)[eworm.de: no valid DMARC record]; RCVD_COUNT_FIVE(0.00)[5]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_NEQ_ENVFROM(0.00)[list@eworm.de,pacman-dev-bounces@lists.archlinux.org]; ARC_NA(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[pacman-dev@lists.archlinux.org]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org From: Christian Hesse By setting the HTTP header 'Cache-Control: no-cache' when returning with the status code 404 (not found) the server can indicate that this is a soft failure. No error message is shown, and server's error count is not increased. This can be used by servers that are not expected to be complete, for example when serving a local cache [0]. In nginx this can be achived by adding a single directive in location block: add_header Cache-Control "no-cache"; Also this is a perfect match for pacredir [1]. [0] https://wiki.archlinux.org/title/Pacman/Tips_and_tricks#Network_shared_pacman_cache [1] https://git.eworm.de/cgit/pacredir/about/ Signed-off-by: Christian Hesse --- lib/libalpm/dload.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 4fa17b35..23034584 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -274,8 +274,10 @@ static size_t dload_parseheader_cb(void *ptr, size_t size, size_t nmemb, void *u { size_t realsize = size * nmemb; const char *fptr, *endptr = NULL; + const char * const cc_header = "Cache-Control:"; const char * const cd_header = "Content-Disposition:"; const char * const fn_key = "filename="; + const char * const nc_key = "no-cache"; struct dload_payload *payload = (struct dload_payload *)user; long respcode; @@ -302,6 +304,15 @@ static size_t dload_parseheader_cb(void *ptr, size_t size, size_t nmemb, void *u } } + /* By setting the HTTP header 'Cache-Control: no-cache' the server can indicate + that this is a soft failure which should not be cached. No error message is + shown, and server's error count is not increased. */ + if(_alpm_raw_ncmp(cc_header, ptr, strlen(cc_header)) == 0) { + if(strstr(ptr, nc_key)) { + payload->errors_ok = 1; + } + } + curl_easy_getinfo(payload->curl, CURLINFO_RESPONSE_CODE, &respcode); if(payload->respcode != respcode) { payload->respcode = respcode;