Skip to content

Commit

Permalink
libfetch: fix proxy connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Perkin authored and github-actions[bot] committed Oct 15, 2024
1 parent 21ae5c4 commit 926deb4
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions net/libfetch/files/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ http_match(const char *str, const char *hdr)
return (hdr);
}

/* Remove whitespace at the end of the buffer */
static void
http_conn_trimright(conn_t *conn)
{
while (conn->buflen &&
isspace((unsigned char)conn->buf[conn->buflen - 1]))
conn->buflen--;
conn->buf[conn->buflen] = '\0';
}

/*
* Get the next header and return the appropriate symbolic code.
*/
Expand All @@ -501,13 +511,20 @@ http_next_header(conn_t *conn, const char **p)
{
int i;

if (fetch_getln(conn) == -1)
return (hdr_syserror);
while (conn->buflen && isspace((unsigned char)conn->buf[conn->buflen - 1]))
conn->buflen--;
conn->buf[conn->buflen] = '\0';
/*
* Have to do the stripping here because of the first line. So
* it's done twice for the subsequent lines. No big deal
*/
http_conn_trimright(conn);

if (conn->buflen == 0)
return (hdr_end);

if (fetch_getln(conn) == -1)
return (hdr_syserror);

http_conn_trimright(conn);

/*
* We could check for malformed headers but we don't really care.
* A valid header starts with a token immediately followed by a
Expand Down Expand Up @@ -780,7 +797,7 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached)
default:
/* ignore */ ;
}
} while (h < hdr_end);
} while (h > hdr_end);
}
if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 &&
fetch_ssl(conn, URL, verbose) == -1) {
Expand Down

0 comments on commit 926deb4

Please sign in to comment.