Skip to content

Commit

Permalink
Close connection before throwing exception
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed May 31, 2016
1 parent e5c4979 commit 5b05db6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Network/Http/Adapter/Stream.php
Expand Up @@ -265,6 +265,7 @@ protected function _send(Request $request)
$url = $request->url();
$this->_open($url);
$content = '';
$timedOut = false;

while (!feof($this->_stream)) {
if ($deadline !== false) {
Expand All @@ -275,12 +276,17 @@ protected function _send(Request $request)

$meta = stream_get_meta_data($this->_stream);
if ($meta['timed_out'] || ($deadline !== false && time() > $deadline)) {
throw new Exception('Connection timed out ' . $url);
$timedOut = true;
break;
}
}
$meta = stream_get_meta_data($this->_stream);
fclose($this->_stream);

if ($timedOut) {
throw new Exception('Connection timed out ' . $url);
}

$headers = $meta['wrapper_data'];
if (isset($headers['headers']) && is_array($headers['headers'])) {
$headers = $headers['headers'];
Expand Down

0 comments on commit 5b05db6

Please sign in to comment.