xbps: import HTTP/1.1 default to keep alive patch

This commit is contained in:
Duncaen 2022-07-03 23:44:02 +02:00
parent c83b8557b0
commit 3d8bb2342d
No known key found for this signature in database
GPG Key ID: 335C1D17EC3D6E35
2 changed files with 56 additions and 1 deletions

View File

@ -0,0 +1,55 @@
From b5954c80db5d7fba2b0635e758126c4d949edbb3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <chocimier@tlen.pl>
Date: Sat, 2 Jul 2022 22:37:08 +0200
Subject: [PATCH] lib/fetch: reuse http connection
With HTTP 1.1 persistent connection is default and Connection
header is not sent.
Before patch, for every file, including 512b signature, there was
done dns query, tls handshake etc.
---
lib/fetch/http.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/fetch/http.c b/lib/fetch/http.c
index 395e7d8f..02b97a51 100644
--- a/lib/fetch/http.c
+++ b/lib/fetch/http.c
@@ -424,7 +424,7 @@ http_cmd(conn_t *conn, const char *fmt, ...)
* Get and parse status line
*/
static int
-http_get_reply(conn_t *conn)
+http_get_reply(conn_t *conn, int *keep_alive)
{
char *p;
@@ -445,6 +445,10 @@ http_get_reply(conn_t *conn)
if (*p == '/') {
if (p[1] != '1' || p[2] != '.' || (p[3] != '0' && p[3] != '1'))
return (HTTP_PROTOCOL_ERROR);
+ /* HTTP/1.1 defaults to the use of "persistent connections" */
+ if (keep_alive && p[3] == '1') {
+ *keep_alive = 1;
+ }
p += 4;
}
if (*p != ' ' ||
@@ -760,7 +764,7 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached)
http_cmd(conn, "\r\n");
- if (http_get_reply(conn) != HTTP_OK) {
+ if (http_get_reply(conn, NULL) != HTTP_OK) {
http_seterr(conn->err);
fetch_close(conn);
return (NULL);
@@ -1011,7 +1015,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
sizeof(val));
/* get reply */
- switch (http_get_reply(conn)) {
+ switch (http_get_reply(conn, &keep_alive)) {
case HTTP_OK:
case HTTP_PARTIAL:
case HTTP_NOT_MODIFIED:

View File

@ -1,7 +1,7 @@
# Template file for 'xbps'
pkgname=xbps
version=0.59.1
revision=6
revision=7
bootstrap=yes
build_style=configure
short_desc="XBPS package system utilities"