From 392eda7ce97b5762025db4b56b781cee5f597fc9 Mon Sep 17 00:00:00 2001 From: kbyanc Date: Wed, 2 Mar 2005 19:09:28 +0000 Subject: Set the TCP_NODELAY socket option and clear TCP_NOPUSH in order to flush any pending HTTP request rather than calling shutdown(2) with SHUT_WR. This makes libfetch (and thus fetch(1)) work again with Squid proxies configured to not allow half-closed connections. Reported by: Pawel Worach (pawel.worach AT telia DOT com) --- lib/libfetch/http.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lib/libfetch/http.c') diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index d0008aa..bac7b0f 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -792,7 +792,7 @@ _http_request(struct url *URL, const char *op, struct url_stat *us, conn_t *conn; struct url *url, *new; int chunked, direct, need_auth, noredirect, verbose; - int e, i, n; + int e, i, n, val; off_t offset, clength, length, size; time_t mtime; const char *p; @@ -913,7 +913,20 @@ _http_request(struct url *URL, const char *op, struct url_stat *us, _http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset); _http_cmd(conn, "Connection: close"); _http_cmd(conn, ""); - shutdown(conn->sd, SHUT_WR); + + /* + * Force the queued request to be dispatched. Normally, one + * would do this with shutdown(2) but squid proxies can be + * configured to disallow such half-closed connections. To + * be compatible with such configurations, fiddle with socket + * options to force the pending data to be written. + */ + val = 0; + setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val, + sizeof(val)); + val = 1; + setsockopt(conn->sd, IPPROTO_TCP, TCP_NODELAY, &val, + sizeof(val)); /* get reply */ switch (_http_get_reply(conn)) { -- cgit v1.1