diff --git a/src/AWS/CRT/HTTP/Headers.php b/src/AWS/CRT/HTTP/Headers.php index 9a04bd3..4744182 100644 --- a/src/AWS/CRT/HTTP/Headers.php +++ b/src/AWS/CRT/HTTP/Headers.php @@ -42,6 +42,6 @@ final class Headers { } public function toArray() { - return array_merge($this->headers); + return $this->headers; } } diff --git a/src/AWS/CRT/HTTP/Message.php b/src/AWS/CRT/HTTP/Message.php index e186daf..a148f16 100644 --- a/src/AWS/CRT/HTTP/Message.php +++ b/src/AWS/CRT/HTTP/Message.php @@ -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() { diff --git a/src/AWS/CRT/HTTP/Request.php b/src/AWS/CRT/HTTP/Request.php index 18d908e..302b7c0 100644 --- a/src/AWS/CRT/HTTP/Request.php +++ b/src/AWS/CRT/HTTP/Request.php @@ -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; } diff --git a/src/tests/HttpMessageTest.php b/src/tests/HttpMessageTest.php index bf0f87b..4928e90 100644 --- a/src/tests/HttpMessageTest.php +++ b/src/tests/HttpMessageTest.php @@ -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);