pear /http2
杂项HTTP工具
v2.0.0
2023-03-22 20:22 UTC
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-09-22 23:48:25 UTC
README
提供用于执行各种HTTP相关操作(如日期格式化、语言协商或HTTP重定向)的静态方法。
功能
- 语言协商
- MIME类型协商
- 字符集协商
- 向URL发送HEAD请求
- 生成绝对URL
- 解析HTTP
Link:头值(RFC 5988)
安装
$ composer require pear/http2
使用方法
语言协商
在Accept-Language:头中的质量因素得到支持,例如:
Accept-Language: en-UK;q=0.7, en-US;q=0.6, no, dk;q=0.8
代码
<?php
$http = new HTTP2();
$langs = array(
'en' => 'locales/en',
'en-US' => 'locales/en',
'en-UK' => 'locales/en',
'de' => 'locales/de',
'de-DE' => 'locales/de',
'de-AT' => 'locales/de',
);
$neg = $http->negotiateLanguage($langs);
$dir = $langs[$neg];
?>
字符集协商
<?php
$http = new HTTP2();
$charsets = array(
'UTF-8',
'ISO-8859-1',
);
$charset = $http->negotiateCharset($charsets);
?>
MIME类型协商
<?php
$http = new HTTP2();
$contentType = array(
'application/xhtml+xml',
'application/xml',
'text/html',
'text/plain',
);
$mime = $http->negotiateMimeType($contentType);
?>