ytake / hungrr
HTTP 请求和响应
0.13.3
2020-07-31 04:46 UTC
Requires
- hhvm: ^4.62
- facebook/hack-http-request-response-interfaces: ^0.3
- hhvm/hhvm-autoload: ^3.0
- hhvm/hsl: ^4.0
- hhvm/hsl-experimental: ^4.50
- ytake/extended-hack-http-request: ^0.1.2
Requires (Dev)
- facebook/fbexpect: ^2.7
- hhvm/hacktest: ^2.0
- hhvm/hhast: ^4.0
README
ytake/hungrr
是一个 Hack 包,包含了对 Hack HTTP 请求和响应接口 的实现
PSR-7 是为 PHP 设计的,不是为 Hack,因此一些决策与 Hack 的类型系统不太兼容。
不支持 PHP
要求
HHVM 4.20.0 及以上版本。
安装
通过 Composer
$ composer install ytake/hungrr
使用
序列化传入请求
use type Ytake\Hungrr\ServerRequestFactory; $request = ServerRequestFactory::fromGlobals();
响应
JSON 响应
构造函数详情
public function __construct( private \HH\Lib\Experimental\IO\WriteHandle $body, StatusCode $status = StatusCode::OK, dict<string, vec<string>> $headers = dict[], protected int $encodingOptions = self::DEFAULT_JSON_FLAGS )
示例
use type Ytake\Hungrr\Uri; use type Ytake\Hungrr\StatusCode; use type Ytake\Hungrr\Response\RedirectResponse; use namespace HH\Lib\Experimental\IO; list($read, $write) = IO\pipe_non_disposable(); await $write->writeAsync(\json_encode(dict[ 'testing' => dict[ 'HHVM' => 'Hack' ] ])));
重定向响应
构造函数详情
public function __construct(
mixed $uri,
Ytake\Hungrr\StatusCode $status,
dict<string, vec<string>> $headers
)
$uri,必须是字符串或 Facebook\Experimental\Http\Message\UriInterface 实例。
示例
use type Ytake\Hungrr\Uri; use type Ytake\Hungrr\StatusCode; use type Ytake\Hungrr\Response\RedirectResponse; // use uri string $r = new RedirectResponse('/foo/bar'); // use uri instance $r = new RedirectResponse(new Uri('https://example.com:10082/foo/bar'));