Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
50
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php
vendored
Normal file
50
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\Internal\Encoding;
|
||||
|
||||
final class Headers {
|
||||
private $headers;
|
||||
|
||||
public function __construct($headers = []) {
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
public static function marshall($headers) {
|
||||
$buf = "";
|
||||
foreach ($headers->headers as $header => $value) {
|
||||
$buf .= Encoding::encodeString($header);
|
||||
$buf .= Encoding::encodeString($value);
|
||||
}
|
||||
return $buf;
|
||||
}
|
||||
|
||||
public static function unmarshall($buf) {
|
||||
$strings = Encoding::readStrings($buf);
|
||||
$headers = [];
|
||||
for ($idx = 0; $idx < count($strings);) {
|
||||
$headers[$strings[$idx++]] = $strings[$idx++];
|
||||
}
|
||||
return new Headers($headers);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
return count($this->headers);
|
||||
}
|
||||
|
||||
public function get($header) {
|
||||
return isset($this->headers[$header]) ? $this->headers[$header] : null;
|
||||
}
|
||||
|
||||
public function set($header, $value) {
|
||||
$this->headers[$header] = $value;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return $this->headers;
|
||||
}
|
||||
}
|
||||
95
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php
vendored
Normal file
95
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\NativeResource;
|
||||
use AWS\CRT\Internal\Encoding;
|
||||
|
||||
abstract class Message extends NativeResource {
|
||||
private $method;
|
||||
private $path;
|
||||
private $query;
|
||||
private $headers;
|
||||
|
||||
public function __construct($method, $path, $query = [], $headers = []) {
|
||||
parent::__construct();
|
||||
$this->method = $method;
|
||||
$this->path = $path;
|
||||
$this->query = $query;
|
||||
$this->headers = new Headers($headers);
|
||||
$this->acquire(self::$crt->http_message_new_from_blob(self::marshall($this)));
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
self::$crt->http_message_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public function toBlob() {
|
||||
return self::$crt->http_message_to_blob($this->native);
|
||||
}
|
||||
|
||||
protected static function marshall($msg) {
|
||||
$buf = "";
|
||||
$buf .= Encoding::encodeString($msg->method);
|
||||
$buf .= Encoding::encodeString($msg->pathAndQuery());
|
||||
$buf .= Headers::marshall($msg->headers);
|
||||
return $buf;
|
||||
}
|
||||
|
||||
protected static function _unmarshall($buf, $class=Message::class) {
|
||||
$method = Encoding::readString($buf);
|
||||
$path_and_query = Encoding::readString($buf);
|
||||
$parts = explode("?", $path_and_query, 2);
|
||||
$path = isset($parts[0]) ? $parts[0] : "";
|
||||
$query = isset($parts[1]) ? $parts[1] : "";
|
||||
$headers = Headers::unmarshall($buf);
|
||||
|
||||
// Turn query params back into a dictionary
|
||||
if (strlen($query)) {
|
||||
$query = rawurldecode($query);
|
||||
$query = explode("&", $query);
|
||||
$query = array_reduce($query, function($params, $pair) {
|
||||
list($param, $value) = explode("=", $pair, 2);
|
||||
$params[$param] = $value;
|
||||
return $params;
|
||||
}, []);
|
||||
} else {
|
||||
$query = [];
|
||||
}
|
||||
|
||||
return new $class($method, $path, $query, $headers->toArray());
|
||||
}
|
||||
|
||||
public function pathAndQuery() {
|
||||
$path = $this->path;
|
||||
$queries = [];
|
||||
foreach ($this->query as $param => $value) {
|
||||
$queries []= urlencode($param) . "=" . urlencode($value);
|
||||
}
|
||||
$query = implode("&", $queries);
|
||||
if (strlen($query)) {
|
||||
$path = implode("?", [$path, $query]);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function method() {
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
public function path() {
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function query() {
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function headers() {
|
||||
return $this->headers;
|
||||
}
|
||||
}
|
||||
32
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php
vendored
Normal file
32
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\IO\InputStream;
|
||||
|
||||
class Request extends Message {
|
||||
private $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 new \InvalidArgumentException('body_stream must be an instance of ' . InputStream::class);
|
||||
}
|
||||
$this->body_stream = $body_stream;
|
||||
}
|
||||
|
||||
public static function marshall($request) {
|
||||
return parent::marshall($request);
|
||||
}
|
||||
|
||||
public static function unmarshall($buf) {
|
||||
return parent::_unmarshall($buf, Request::class);
|
||||
}
|
||||
|
||||
public function body_stream() {
|
||||
return $this->body_stream;
|
||||
}
|
||||
}
|
||||
27
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php
vendored
Normal file
27
vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
class Response extends Message {
|
||||
private $status_code;
|
||||
|
||||
public function __construct($method, $path, $query, $headers, $status_code) {
|
||||
parent::__construct($method, $path, $query, $headers);
|
||||
$this->status_code = $status_code;
|
||||
}
|
||||
|
||||
public static function marshall($response) {
|
||||
return parent::marshall($response);
|
||||
}
|
||||
|
||||
public static function unmarshall($buf) {
|
||||
return parent::_unmarshall($buf, Response::class);
|
||||
}
|
||||
|
||||
public function status_code() {
|
||||
return $this->status_code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user