Idiomatic fixes from previous PRs (#20)

* Various idiomatic feedback from PHP team

* Additional fixes after debugging tests
This commit is contained in:
Justin Boswell
2021-03-25 15:13:23 -04:00
committed by GitHub
parent 9c9422c21f
commit 531330e1b2
4 changed files with 14 additions and 13 deletions
+1 -1
View File
@@ -42,6 +42,6 @@ final class Headers {
} }
public function toArray() { public function toArray() {
return array_merge($this->headers); return $this->headers;
} }
} }
+3 -4
View File
@@ -3,7 +3,6 @@
namespace AWS\CRT\HTTP; namespace AWS\CRT\HTTP;
use AWS\CRT\NativeResource; use AWS\CRT\NativeResource;
use AWS\CRT\Internal\Encoding; use AWS\CRT\Internal\Encoding;
abstract class Message extends NativeResource { abstract class Message extends NativeResource {
@@ -12,11 +11,11 @@ abstract class Message extends NativeResource {
private $query; private $query;
private $headers; private $headers;
public function __construct($method, $path, $query = [], $headers = null) { public function __construct($method, $path, $query = [], $headers = []) {
$this->method = $method; $this->method = $method;
$this->path = $path; $this->path = $path;
$this->query = $query; $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))); $this->acquire(self::$crt->http_message_new_from_blob(self::marshall($this)));
} }
@@ -54,7 +53,7 @@ abstract class Message extends NativeResource {
$query = []; $query = [];
} }
return new $class($method, $path, $query, $headers); return new $class($method, $path, $query, $headers->toArray());
} }
public function pathAndQuery() { public function pathAndQuery() {
+6 -1
View File
@@ -2,11 +2,16 @@
namespace AWS\CRT\HTTP; namespace AWS\CRT\HTTP;
use AWS\CRT\IO\InputStream;
class Request extends Message { class Request extends Message {
private $body_stream = null; 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); 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; $this->body_stream = $body_stream;
} }
+4 -7
View File
@@ -37,11 +37,10 @@ final class HttpMessageTest extends CrtTestCase {
} }
public function testRequestMarshalling() { public function testRequestMarshalling() {
$headers_array = [ $headers = [
"host" => "s3.amazonaws.com", "host" => "s3.amazonaws.com",
"test" => "this is a test header value" "test" => "this is a test header value"
]; ];
$headers = new Headers($headers_array);
$method = "GET"; $method = "GET";
$path = "/index.php"; $path = "/index.php";
$query = []; $query = [];
@@ -54,11 +53,10 @@ final class HttpMessageTest extends CrtTestCase {
} }
public function testRequestMarshallingWithQueryParams() { public function testRequestMarshallingWithQueryParams() {
$headers_array = [ $headers = [
"host" => "s3.amazonaws.com", "host" => "s3.amazonaws.com",
"test" => "this is a test header value" "test" => "this is a test header value"
]; ];
$headers = new Headers($headers_array);
$method = "GET"; $method = "GET";
$path = "/index.php"; $path = "/index.php";
$query = [ $query = [
@@ -76,18 +74,17 @@ final class HttpMessageTest extends CrtTestCase {
} }
public function testResponseMarshalling() { public function testResponseMarshalling() {
$headers_array = [ $headers = [
"content-length" => "42", "content-length" => "42",
"test" => "this is a test header value" "test" => "this is a test header value"
]; ];
$headers = new Headers($headers_array);
$method = "GET"; $method = "GET";
$path = "/index.php"; $path = "/index.php";
$query = [ $query = [
'response' => '1' 'response' => '1'
]; ];
$msg = new Response($method, $path, $query, $headers, 400); $msg = new Response($method, $path, $query, $headers, 200);
$msg_buf = Request::marshall($msg); $msg_buf = Request::marshall($msg);
$msg_copy = Request::unmarshall($msg_buf); $msg_copy = Request::unmarshall($msg_buf);