Skip to content

Commit 2061f97

Browse files
committed
Curl 使用完连接后执行 curl_reset
1 parent 701517d commit 2061f97

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/YurunHttp/Handler/Curl.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function close()
104104
{
105105
if ($this->poolIsEnabled)
106106
{
107+
curl_reset($this->handler);
107108
CurlHttpConnectionManager::getInstance()->release($this->poolKey, $this->handler);
108109
}
109110
else
@@ -229,11 +230,15 @@ public function send(&$request)
229230
}
230231
finally
231232
{
232-
if ($poolIsEnabled && $this->handler)
233+
if ($this->handler)
233234
{
234-
// @phpstan-ignore-next-line
235-
$httpConnectionManager->release($this->poolKey, $this->handler);
236-
$this->handler = null;
235+
curl_reset($this->handler);
236+
if ($poolIsEnabled)
237+
{
238+
// @phpstan-ignore-next-line
239+
$httpConnectionManager->release($this->poolKey, $this->handler);
240+
$this->handler = null;
241+
}
237242
}
238243
}
239244
}

src/YurunHttp/Traits/THandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function parseRedirectLocation($location, $currentUri)
3333
{
3434
$uri = $currentUri;
3535
$path = $currentUri->getPath();
36-
if('/' !== substr($path, -1, 1))
36+
if ('/' !== substr($path, -1, 1))
3737
{
3838
$path = $path . '/';
3939
}

tests/unit/HttpRequestTest/HttpRequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,4 +663,21 @@ public function testHead()
663663
$this->assertResponse($response);
664664
});
665665
}
666+
667+
/**
668+
* @see https://github.com/Yurunsoft/YurunHttp/issues/19
669+
*
670+
* @return void
671+
*/
672+
public function testBug19()
673+
{
674+
$this->call(function () {
675+
$http = new HttpRequest();
676+
$response = $http->head('https://www.baidu.com');
677+
$this->assertResponse($response);
678+
$response = $http->get('https://www.baidu.com');
679+
$this->assertResponse($response);
680+
$this->assertTrue('' != $response->body());
681+
});
682+
}
666683
}

0 commit comments

Comments
 (0)