summaryrefslogtreecommitdiff
path: root/libfetch/common.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-01-19 16:37:39 +0200
committerTimo Teräs <timo.teras@iki.fi>2021-01-19 16:42:38 +0200
commitacca5cbff088397a960a24cd3600e772b572308d (patch)
tree288004d39f7e8139ce4cfd823ec2674ff5d58f60 /libfetch/common.c
parentd430a989761e293e0fb042dcfe575cabdd95805a (diff)
downloadapk-tools-acca5cbff088397a960a24cd3600e772b572308d.tar.gz
apk-tools-acca5cbff088397a960a24cd3600e772b572308d.tar.bz2
apk-tools-acca5cbff088397a960a24cd3600e772b572308d.tar.xz
apk-tools-acca5cbff088397a960a24cd3600e772b572308d.zip
libfetch: fix connection pooling for proxied http/https requests
The connection pooling was broken in two ways: 1. The original URL was always used as the connection pool URL, resulting in duplicate connections to the proxy for http URLs (each http URL would get separate proxy connection) 2. The cache_url stored was always the socket level connect URL. In case of HTTPS, the lookup was done done with the real URL, but the proxy URL was stored as the "cache URL". Thus HTTPS CONNECT connections were never re-used. This fixes the code with following logic: 1. The cache key url is the real URL when no-proxy, or when HTTPS with proxy (the socket is connected to proxy, but logically it is connected to the real URL due to HTTP CONNECT request). And for HTTP with proxy, it's the proxy URL so same proxy connection can be reused for all requests going through it. 2. fetch_connect() now gets cache key URL separately, and it always gets the same value as the fetch_cache_get() calls.
Diffstat (limited to 'libfetch/common.c')
-rw-r--r--libfetch/common.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libfetch/common.c b/libfetch/common.c
index aabe218..e91b0c6 100644
--- a/libfetch/common.c
+++ b/libfetch/common.c
@@ -251,7 +251,7 @@ fetch_bind(int sd, int af, const char *addr)
* Establish a TCP connection to the specified port on the specified host.
*/
conn_t *
-fetch_connect(struct url *url, int af, int verbose)
+fetch_connect(struct url *cache_url, struct url *url, int af, int verbose)
{
conn_t *conn;
char pbuf[10];
@@ -303,7 +303,7 @@ fetch_connect(struct url *url, int af, int verbose)
close(sd);
return (NULL);
}
- conn->cache_url = fetchCopyURL(url);
+ conn->cache_url = fetchCopyURL(cache_url);
conn->cache_af = af;
return (conn);
}