Skip to content

Commit f96e372

Browse files
authored
Upgrade hyperf/engine to v2.11. (#6698)
1 parent 9753469 commit f96e372

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": ">=8.1",
1414
"hyperf/codec": "~3.1.0",
15-
"hyperf/engine": "^2.7",
15+
"hyperf/engine": "^2.11",
1616
"hyperf/support": "~3.1.0",
1717
"laminas/laminas-mime": "^2.7",
1818
"psr/http-message": "^1.0|^2.0",

src/Base/Request.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Hyperf\HttpMessage\Base;
1414

15+
use Hyperf\Engine\Http\Http;
1516
use Hyperf\HttpMessage\Stream\SwooleStream;
1617
use Hyperf\HttpMessage\Uri\Uri;
1718
use InvalidArgumentException;
@@ -245,20 +246,12 @@ public function setRequestTarget(string $requestTarget): static
245246

246247
public function toString(bool $withoutBody = false): string
247248
{
248-
$headerString = '';
249-
foreach ($this->getStandardHeaders() as $key => $values) {
250-
foreach ($values as $value) {
251-
$headerString .= sprintf("%s: %s\r\n", $key, $value);
252-
}
253-
}
254-
255-
return sprintf(
256-
"%s %s HTTP/%s\r\n%s\r\n%s",
249+
return Http::packRequest(
257250
$this->getMethod(),
258251
$this->getUri()->getPath(),
259-
$this->getProtocolVersion(),
260-
$headerString,
261-
$withoutBody ? '' : $this->getBody()
252+
$this->getStandardHeaders(),
253+
$withoutBody ? '' : (string) $this->getBody(),
254+
$this->getProtocolVersion()
262255
);
263256
}
264257

src/Base/Response.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Hyperf\HttpMessage\Base;
1414

15+
use Hyperf\Engine\Http\Http;
1516
use InvalidArgumentException;
1617
use Psr\Http\Message\ResponseInterface;
1718
use Stringable;
@@ -342,19 +343,12 @@ public function isEmpty(): bool
342343

343344
public function toString(bool $withoutBody = false): string
344345
{
345-
$headerString = '';
346-
foreach ($this->getStandardHeaders() as $key => $values) {
347-
foreach ($values as $value) {
348-
$headerString .= sprintf("%s: %s\r\n", $key, $value);
349-
}
350-
}
351-
return sprintf(
352-
"HTTP/%s %s %s\r\n%s\r\n%s",
353-
$this->getProtocolVersion(),
346+
return Http::packResponse(
354347
$this->getStatusCode(),
355348
$this->getReasonPhrase(),
356-
$headerString,
357-
$withoutBody ? '' : $this->getBody()
349+
$this->getStandardHeaders(),
350+
$withoutBody ? '' : (string) $this->getBody(),
351+
$this->getProtocolVersion()
358352
);
359353
}
360354

tests/ResponseTest.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Hyperf\Codec\Json;
1616
use Hyperf\Engine\Http\WritableConnection;
1717
use Hyperf\HttpMessage\Cookie\Cookie;
18+
use Hyperf\HttpMessage\Server\Request;
1819
use Hyperf\HttpMessage\Server\Response;
1920
use Hyperf\HttpMessage\Stream\SwooleStream;
21+
use Hyperf\HttpMessage\Uri\Uri;
2022
use Mockery;
2123
use PHPUnit\Framework\Attributes\CoversNothing;
2224
use PHPUnit\Framework\TestCase;
@@ -73,7 +75,7 @@ public function testWrite()
7375
$this->assertTrue($status);
7476
}
7577

76-
public function testToString()
78+
public function testToResponseString()
7779
{
7880
$response = $this->newResponse();
7981
if (! $response instanceof ResponsePlusInterface) {
@@ -95,6 +97,25 @@ public function testToString()
9597
", $response->toString(true));
9698
}
9799

100+
public function testToRequestString()
101+
{
102+
$request = new Request('GET', new Uri('https://www.baidu.com/'), body: 'q=Hyperf');
103+
104+
$this->assertSame("GET / HTTP/1.1\r
105+
host: www.baidu.com\r
106+
Connection: close\r
107+
Content-Length: 8\r
108+
\r
109+
q=Hyperf", $request->toString());
110+
111+
$this->assertSame("GET / HTTP/1.1\r
112+
host: www.baidu.com\r
113+
Connection: close\r
114+
Content-Length: 8\r
115+
\r
116+
", $request->toString(true));
117+
}
118+
98119
protected function newResponse()
99120
{
100121
return new Response();

tests/ServerRequestTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
* @coversNothing
4141
*/
4242
#[CoversNothing]
43-
/**
44-
* @internal
45-
* @coversNothing
46-
*/
4743
class ServerRequestTest extends TestCase
4844
{
4945
protected function tearDown(): void

0 commit comments

Comments
 (0)