Skip to content

Commit e0f50f4

Browse files
authored
Merge pull request #20 from Yurunsoft/fix-19
修复 bug #19
2 parents aba10dc + 2061f97 commit e0f50f4

3 files changed

Lines changed: 33 additions & 8 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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ public function parseRedirectLocation($location, $currentUri)
3131
}
3232
else
3333
{
34-
$path = \dirname($currentUri);
35-
if ('\\' === \DIRECTORY_SEPARATOR && false !== strpos($path, \DIRECTORY_SEPARATOR))
34+
$uri = $currentUri;
35+
$path = $currentUri->getPath();
36+
if ('/' !== substr($path, -1, 1))
3637
{
37-
$path = str_replace(\DIRECTORY_SEPARATOR, '/', $path);
38+
$path = $path . '/';
3839
}
39-
$uri = new Uri($path . '/' . $location);
40+
$path .= $location;
41+
$uri = $uri->withPath($path);
4042
}
43+
$uri = $uri->withHost($currentUri->getHost())->withPort($currentUri->getPort());
4144
}
4245
else
4346
{

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)