summaryrefslogtreecommitdiffstats
path: root/usr.sbin/portsnap/phttpget
diff options
context:
space:
mode:
authorcperciva <cperciva@FreeBSD.org>2007-06-30 19:48:28 +0000
committercperciva <cperciva@FreeBSD.org>2007-06-30 19:48:28 +0000
commit64e90b3614c81f0b61efc2544e1baea59ea7e81c (patch)
tree8807e0811f3efad107ec1c5565ab49fd32a8fb3a /usr.sbin/portsnap/phttpget
parent4db9e9bfd8b24b76fd8c30e12d0bc69afa75044a (diff)
downloadFreeBSD-src-64e90b3614c81f0b61efc2544e1baea59ea7e81c.zip
FreeBSD-src-64e90b3614c81f0b61efc2544e1baea59ea7e81c.tar.gz
Add support for HTTP/1.0 Persistent Connections to phttpget. Requests are
be marked as HTTP/1.1 but "Connection: Keep-Alive" is added; this convinces HTTP/1.0 servers and proxies to hold the TCP connection open despite not being able to use HTTP pipelining. This dramatically cuts down on the number of TCP connections (and thus port numbers) used by portsnap when talking to an HTTP/1.0 proxy (e.g., squid), and has the side benefit of improving performance in those cases. Tested by: simon Approved by: re (kensmith) MFC After: 1 week
Diffstat (limited to 'usr.sbin/portsnap/phttpget')
-rw-r--r--usr.sbin/portsnap/phttpget/phttpget.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/usr.sbin/portsnap/phttpget/phttpget.c b/usr.sbin/portsnap/phttpget/phttpget.c
index 315af00..ffd14c3 100644
--- a/usr.sbin/portsnap/phttpget/phttpget.c
+++ b/usr.sbin/portsnap/phttpget/phttpget.c
@@ -211,7 +211,7 @@ makerequest(char ** buf, char * path, char * server, int connclose)
env_HTTP_PROXY ? server : "",
path, server, env_HTTP_USER_AGENT,
proxyauth ? proxyauth : "",
- connclose ? "Connection: Close\r\n" : "");
+ connclose ? "Connection: Close\r\n" : "Connection: Keep-Alive\r\n");
if (buflen == -1)
err(1, "asprintf");
return(buflen);
@@ -307,6 +307,7 @@ main(int argc, char *argv[])
int nreq = 0; /* Number of next request to send */
int nres = 0; /* Number of next reply to receive */
int pipelined = 0; /* != 0 if connection in pipelined mode. */
+ int keepalive; /* != 0 if HTTP/1.0 keep-alive rcvd. */
int sd = -1; /* Socket descriptor */
int sdflags = 0; /* Flags on the socket sd */
int fd = -1; /* Descriptor for download target file */
@@ -444,6 +445,7 @@ main(int argc, char *argv[])
statuscode = 0;
contentlength = -1;
chunked = 0;
+ keepalive = 0;
do {
/* Get a header line */
error = readln(sd, resbuf, &resbuflen, &resbufpos);
@@ -497,11 +499,16 @@ main(int argc, char *argv[])
continue;
}
- /* Check for "Connection: close" header */
+ /*
+ * Check for "Connection: close" or
+ * "Connection: Keep-Alive" header
+ */
if (strncmp(hln, "Connection:", 11) == 0) {
hln += 11;
if (strstr(hln, "close") != NULL)
pipelined = 0;
+ if (strstr(hln, "Keep-Alive") != NULL)
+ keepalive = 1;
/* Next header... */
continue;
@@ -673,7 +680,7 @@ main(int argc, char *argv[])
* If necessary, clean up this connection so that we
* can start a new one.
*/
- if (pipelined == 0)
+ if (pipelined == 0 && keepalive == 0)
goto cleanupconn;
continue;
OpenPOWER on IntegriCloud