mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-17 17:47:12 +00:00
Idiomatic fixes from previous PRs (#20)
* Various idiomatic feedback from PHP team * Additional fixes after debugging tests
This commit is contained in:
@@ -42,6 +42,6 @@ final class Headers {
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return array_merge($this->headers);
|
||||
return $this->headers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\NativeResource;
|
||||
|
||||
use AWS\CRT\Internal\Encoding;
|
||||
|
||||
abstract class Message extends NativeResource {
|
||||
@@ -12,11 +11,11 @@ abstract class Message extends NativeResource {
|
||||
private $query;
|
||||
private $headers;
|
||||
|
||||
public function __construct($method, $path, $query = [], $headers = null) {
|
||||
public function __construct($method, $path, $query = [], $headers = []) {
|
||||
$this->method = $method;
|
||||
$this->path = $path;
|
||||
$this->query = $query;
|
||||
$this->headers = !is_null($headers) ? $headers : new Headers();
|
||||
$this->headers = new Headers($headers);
|
||||
$this->acquire(self::$crt->http_message_new_from_blob(self::marshall($this)));
|
||||
}
|
||||
|
||||
@@ -54,7 +53,7 @@ abstract class Message extends NativeResource {
|
||||
$query = [];
|
||||
}
|
||||
|
||||
return new $class($method, $path, $query, $headers);
|
||||
return new $class($method, $path, $query, $headers->toArray());
|
||||
}
|
||||
|
||||
public function pathAndQuery() {
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\IO\InputStream;
|
||||
|
||||
class Request extends Message {
|
||||
private $body_stream = null;
|
||||
|
||||
public function __construct($method, $path, $query = [], $headers = null, $body_stream = null) {
|
||||
public function __construct($method, $path, $query = [], $headers = [], $body_stream = null) {
|
||||
parent::__construct($method, $path, $query, $headers);
|
||||
if (!is_null($body_stream) && !($body_stream instanceof InputStream)) {
|
||||
throw \InvalidArgumentException('body_stream must be an ' . InputStream::class);
|
||||
}
|
||||
$this->body_stream = $body_stream;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,10 @@ final class HttpMessageTest extends CrtTestCase {
|
||||
}
|
||||
|
||||
public function testRequestMarshalling() {
|
||||
$headers_array = [
|
||||
$headers = [
|
||||
"host" => "s3.amazonaws.com",
|
||||
"test" => "this is a test header value"
|
||||
];
|
||||
$headers = new Headers($headers_array);
|
||||
$method = "GET";
|
||||
$path = "/index.php";
|
||||
$query = [];
|
||||
@@ -54,11 +53,10 @@ final class HttpMessageTest extends CrtTestCase {
|
||||
}
|
||||
|
||||
public function testRequestMarshallingWithQueryParams() {
|
||||
$headers_array = [
|
||||
$headers = [
|
||||
"host" => "s3.amazonaws.com",
|
||||
"test" => "this is a test header value"
|
||||
];
|
||||
$headers = new Headers($headers_array);
|
||||
$method = "GET";
|
||||
$path = "/index.php";
|
||||
$query = [
|
||||
@@ -76,18 +74,17 @@ final class HttpMessageTest extends CrtTestCase {
|
||||
}
|
||||
|
||||
public function testResponseMarshalling() {
|
||||
$headers_array = [
|
||||
$headers = [
|
||||
"content-length" => "42",
|
||||
"test" => "this is a test header value"
|
||||
];
|
||||
$headers = new Headers($headers_array);
|
||||
$method = "GET";
|
||||
$path = "/index.php";
|
||||
$query = [
|
||||
'response' => '1'
|
||||
];
|
||||
|
||||
$msg = new Response($method, $path, $query, $headers, 400);
|
||||
$msg = new Response($method, $path, $query, $headers, 200);
|
||||
$msg_buf = Request::marshall($msg);
|
||||
$msg_copy = Request::unmarshall($msg_buf);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user