phpstandard / raw-request-factory
一个库,用于根据RFC2616第5节创建一个服务器请求,该请求从原始HTTP请求字符串实现PSR-7 ServerRequestInterface,反之亦然
1.0.1
2021-03-20 22:28 UTC
Requires
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
This package is auto-updated.
Last update: 2024-09-21 06:21:15 UTC
README
一个库,用于根据RFC2616第5节,从原始HTTP请求字符串创建一个实现PSR-7 ServerRequestInterface的服务器请求,反之亦然。
安装
$ composer require phpstandard/raw-request-factory
基本用法
<?php use Framework\Http\RawRequestFactory; // Any implementation of the Psr\Http\Message\ServerRequestFactoryInterface $server_request_factory = new ServerRequestFactory; // Any implementation of the Psr\Http\Message\StreamFactoryInterface $stream_factory = new StreamFactory; // In most cases this will be a server request // captured from globals (a real http request to the server). $server_request = $server_request_factory->createServerRequest('POST', 'https://example.com'); $factory = new RawRequestFactory($server_request_factory, $stream_factory); // Create a raw HTTP request string from the ServerRequestFactoryInterface implementation $raw_request = $factory->createRawRequest($server_request); // Create a server request from the raw HTTP request string $new_server_request = $factory->createServerRequest($raw_request);
注意
尽管RawRequestFactory依赖于ServerRequestFactoryInterface和StreamFactoryInterface实现,但这两个接口的实现超出了这个库的范围。
此库无法与带有Content-Type: multipart/form-data; boundary=something头部的POST请求正常工作
待办事项
- 添加单元测试
- 改进库,使其能够与带有
Content-Type: multipart/form-data; boundary=something头部的POST请求一起工作。