From fd34acb2b79aeec3dfb886e1218e763d41ca6ef9 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 13 May 2016 20:53:22 +1000 Subject: [PATCH] Force closing keep-alive connections on old cURL cURL <7.22 seems to hold the request open if the connection is keep-alive and the buffer hasn't been filled. Changing to single connections is slightly less efficient (although unnoticable in most uses), but should fix this issue. If you need keep-alive, set the Connection header manually. --- library/Requests/Transport/cURL.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/Requests/Transport/cURL.php b/library/Requests/Transport/cURL.php index 5f5c5dfb0..04914440e 100755 --- a/library/Requests/Transport/cURL.php +++ b/library/Requests/Transport/cURL.php @@ -309,6 +309,11 @@ public function &get_subrequest_handle($url, $headers, $data, $options) { protected function setup_handle($url, $headers, $data, $options) { $options['hooks']->dispatch('curl.before_request', array(&$this->handle)); + // Force closing the connection for old versions of cURL (<7.22). + if ( ! isset( $headers['Connection'] ) ) { + $headers['Connection'] = 'close'; + } + $headers = Requests::flatten($headers); if (!empty($data)) {