Skip to content

Commit b5954c8

Browse files
ChocimierDuncaen
authored andcommitted
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.
1 parent 48556b7 commit b5954c8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/fetch/http.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ http_cmd(conn_t *conn, const char *fmt, ...)
424424
* Get and parse status line
425425
*/
426426
static int
427-
http_get_reply(conn_t *conn)
427+
http_get_reply(conn_t *conn, int *keep_alive)
428428
{
429429
char *p;
430430

@@ -445,6 +445,10 @@ http_get_reply(conn_t *conn)
445445
if (*p == '/') {
446446
if (p[1] != '1' || p[2] != '.' || (p[3] != '0' && p[3] != '1'))
447447
return (HTTP_PROTOCOL_ERROR);
448+
/* HTTP/1.1 defaults to the use of "persistent connections" */
449+
if (keep_alive && p[3] == '1') {
450+
*keep_alive = 1;
451+
}
448452
p += 4;
449453
}
450454
if (*p != ' ' ||
@@ -760,7 +764,7 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached)
760764

761765
http_cmd(conn, "\r\n");
762766

763-
if (http_get_reply(conn) != HTTP_OK) {
767+
if (http_get_reply(conn, NULL) != HTTP_OK) {
764768
http_seterr(conn->err);
765769
fetch_close(conn);
766770
return (NULL);
@@ -1011,7 +1015,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
10111015
sizeof(val));
10121016

10131017
/* get reply */
1014-
switch (http_get_reply(conn)) {
1018+
switch (http_get_reply(conn, &keep_alive)) {
10151019
case HTTP_OK:
10161020
case HTTP_PARTIAL:
10171021
case HTTP_NOT_MODIFIED:

0 commit comments

Comments
 (0)