Skip to content

Commit

Permalink
convert uri to path
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Apr 17, 2024
1 parent f2d86bb commit 26e0b65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class Http implements HttpContract
{
public static function packRequest(string $method, string|Stringable $uri, array $headers = [], string|Stringable $body = '', string $protocolVersion = HttpContract::DEFAULT_PROTOCOL_VERSION): string
public static function packRequest(string $method, string|Stringable $path, array $headers = [], string|Stringable $body = '', string $protocolVersion = HttpContract::DEFAULT_PROTOCOL_VERSION): string
{
$headerString = '';
foreach ($headers as $key => $values) {
Expand All @@ -29,7 +29,7 @@ public static function packRequest(string $method, string|Stringable $uri, array
return sprintf(
"%s %s HTTP/%s\r\n%s\r\n%s",
$method,
$uri,
$path,
$protocolVersion,
$headerString,
$body
Expand Down
10 changes: 2 additions & 8 deletions tests/Cases/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@ public function testHttpPackRequest()
{
$data = Http::packRequest('GET', '/', ['Content-Type' => 'application/json'], 'Hello World');

$this->assertSame("GET / HTTP/1.1\r
Content-Type: application/json\r
\r
Hello World", $data);
$this->assertSame("GET / HTTP/1.1\r\nContent-Type: application/json\r\n\r\nHello World", $data);
}

public function testHttpPackResponse()
{
$data = Http::packResponse(200, 'OK', ['Content-Type' => 'application/json'], 'Hello World');

$this->assertSame("HTTP/1.1 200 OK\r
Content-Type: application/json\r
\r
Hello World", $data);
$this->assertSame("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\nHello World", $data);
}
}

0 comments on commit 26e0b65

Please sign in to comment.