Skip to content

Commit

Permalink
Upgrade hyperf/engine to v2.11. (#6698)
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo authored Apr 17, 2024
1 parent 9753469 commit f96e372
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": ">=8.1",
"hyperf/codec": "~3.1.0",
"hyperf/engine": "^2.7",
"hyperf/engine": "^2.11",
"hyperf/support": "~3.1.0",
"laminas/laminas-mime": "^2.7",
"psr/http-message": "^1.0|^2.0",
Expand Down
17 changes: 5 additions & 12 deletions src/Base/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Hyperf\HttpMessage\Base;

use Hyperf\Engine\Http\Http;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpMessage\Uri\Uri;
use InvalidArgumentException;
Expand Down Expand Up @@ -245,20 +246,12 @@ public function setRequestTarget(string $requestTarget): static

public function toString(bool $withoutBody = false): string
{
$headerString = '';
foreach ($this->getStandardHeaders() as $key => $values) {
foreach ($values as $value) {
$headerString .= sprintf("%s: %s\r\n", $key, $value);
}
}

return sprintf(
"%s %s HTTP/%s\r\n%s\r\n%s",
return Http::packRequest(
$this->getMethod(),
$this->getUri()->getPath(),
$this->getProtocolVersion(),
$headerString,
$withoutBody ? '' : $this->getBody()
$this->getStandardHeaders(),
$withoutBody ? '' : (string) $this->getBody(),
$this->getProtocolVersion()
);
}

Expand Down
16 changes: 5 additions & 11 deletions src/Base/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Hyperf\HttpMessage\Base;

use Hyperf\Engine\Http\Http;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Stringable;
Expand Down Expand Up @@ -342,19 +343,12 @@ public function isEmpty(): bool

public function toString(bool $withoutBody = false): string
{
$headerString = '';
foreach ($this->getStandardHeaders() as $key => $values) {
foreach ($values as $value) {
$headerString .= sprintf("%s: %s\r\n", $key, $value);
}
}
return sprintf(
"HTTP/%s %s %s\r\n%s\r\n%s",
$this->getProtocolVersion(),
return Http::packResponse(
$this->getStatusCode(),
$this->getReasonPhrase(),
$headerString,
$withoutBody ? '' : $this->getBody()
$this->getStandardHeaders(),
$withoutBody ? '' : (string) $this->getBody(),
$this->getProtocolVersion()
);
}

Expand Down
23 changes: 22 additions & 1 deletion tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Hyperf\Codec\Json;
use Hyperf\Engine\Http\WritableConnection;
use Hyperf\HttpMessage\Cookie\Cookie;
use Hyperf\HttpMessage\Server\Request;
use Hyperf\HttpMessage\Server\Response;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpMessage\Uri\Uri;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -73,7 +75,7 @@ public function testWrite()
$this->assertTrue($status);
}

public function testToString()
public function testToResponseString()
{
$response = $this->newResponse();
if (! $response instanceof ResponsePlusInterface) {
Expand All @@ -95,6 +97,25 @@ public function testToString()
", $response->toString(true));
}

public function testToRequestString()
{
$request = new Request('GET', new Uri('https://www.baidu.com/'), body: 'q=Hyperf');

$this->assertSame("GET / HTTP/1.1\r
host: www.baidu.com\r
Connection: close\r
Content-Length: 8\r
\r
q=Hyperf", $request->toString());

$this->assertSame("GET / HTTP/1.1\r
host: www.baidu.com\r
Connection: close\r
Content-Length: 8\r
\r
", $request->toString(true));
}

protected function newResponse()
{
return new Response();
Expand Down
4 changes: 0 additions & 4 deletions tests/ServerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
* @coversNothing
*/
#[CoversNothing]
/**
* @internal
* @coversNothing
*/
class ServerRequestTest extends TestCase
{
protected function tearDown(): void
Expand Down

0 comments on commit f96e372

Please sign in to comment.