PSR HTTP Message implementations

Overview

laminas-diactoros

Build Status

Diactoros (pronunciation: /dɪʌktɒrɒs/): an epithet for Hermes, meaning literally, "the messenger."

This package supercedes and replaces phly/http.

laminas-diactoros is a PHP package containing implementations of the PSR-7 HTTP message interfaces and PSR-17 HTTP message factory interfaces.

Documentation

Documentation is available at:

Source files for documentation are in the docs/ tree.

Comments
  • Allow installation on PHP 8.

    Allow installation on PHP 8.

    | Q | A |-------------- | ------ | Documentation | no | Bugfix | no | BC Break | no | New Feature | no | RFC | yes | QA | no

    Description

    Enhancement 
    opened by ADmad 26
  • Add ImageResponse?

    Add ImageResponse?

    How about adding an Zend\Diactoros\Response\ImageResponse that supports the most common file types like JPG, GIF and PNG? How could this be archieved?


    Originally posted by @RalfEggert at https://github.com/zendframework/zend-diactoros/issues/141

    Won't Fix 
    opened by weierophinney 12
  • Fix prefer lowest compatibility

    Fix prefer lowest compatibility

    Trying to fix

    1) IdeHelper\Test\TestCase\Annotator\ClassAnnotatorTask\TestClassAnnotatorTaskTest::testAnnotate
    TypeError: Return value of Zend\Diactoros\marshalUriFromSapi() must be an instance of Zend\Diactoros\Uri, instance of Laminas\Diactoros\Uri returned
    /home/travis/build/dereuromark/cakephp-ide-helper/vendor/laminas/laminas-diactoros/src/functions/marshal_uri_from_sapi.legacy.php:20
    

    https://travis-ci.org/dereuromark/cakephp-ide-helper/jobs/635958965?utm_medium=notification&utm_source=github_status

    But I am not sure if this actually fixes things. Tests are still failing https://github.com/dereuromark/cakephp-ide-helper/pull/168

    I would expect prefer-lowest to not have aliasing issues as this compromises those important travis checks.

    Won't Fix 
    opened by dereuromark 7
  • Fixed `UploadedFile::moveTo()` so it actually removes the original file when used in CLI context, and doesn't leave orphaned files

    Fixed `UploadedFile::moveTo()` so it actually removes the original file when used in CLI context, and doesn't leave orphaned files

    Signed-off-by: katsuren [email protected] UploadedFile::moveTo doesn't work in CLI. Original file leave it as is.

    | Q | A |-------------- | ------ | Documentation | no | Bugfix | yes | BC Break | no | New Feature | no | RFC | no | QA | no

    Description

    Calling UploadedFile::moveTo in CLI, it just copies the file to the targetPath. In addition to this, the stream grabs the original file, so it cannot delete the file, and I cannot access the stream so I couldn't release the file pointer. In a test for uploading file, I want to remove the uploaded file to keep clean the test folder.

    Bug Enhancement 
    opened by k2rn 5
  • Add `UriFactory::createFromSapi()`

    Add `UriFactory::createFromSapi()`

    | Q | A |-------------- | ------ | Documentation | yes | Bugfix | no | BC Break | no | New Feature | yes | RFC | yes | QA | no

    Description

    This method will provide a public API to create Uri instances from SERVER context. This helps libraries that depend on diactoros and have their own ServerRequest or Uri implementations use the logic in diactoros more efficiently.

    I wanted to get a rough draft of this up for feedback. If it is headed in the right direction, I have a few TODOs remaining:

    • [ ] Complete the tests (coverage isn't quite on par with the rest of the library).
    • [ ] Write documentation. I was thinking of putting it the factories section, but would appreciate any direction here.

    If there are other requirements that need to be met let me know :smile:

    Refs #122

    Enhancement 
    opened by markstory 4
  • Could ServerRequestFactory::marshallUriFromSapi() be made public?

    Could ServerRequestFactory::marshallUriFromSapi() be made public?

    Feature Request

    | Q | A |------------ | ------ | New Feature | yes | RFC | yes | BC Break | yes

    Summary

    :wave: from your friends at the CakePHP project, we've been longtime users of diactoros :bow: We recently learned of the plans to deprecate and remove marshalUriFromSapi and eventually remove it.

    https://github.com/laminas/laminas-diactoros/blob/e5b6419fea007b8b4a71034edc8ec96c88d4c57d/src/functions/marshal_uri_from_sapi.php#L30-L36

    The other implementation (ServerRequestFactory::marshallUriFromSapi()) is currently private.

    https://github.com/laminas/laminas-diactoros/blob/e5b6419fea007b8b4a71034edc8ec96c88d4c57d/src/ServerRequestFactory.php#L124

    Is there any appetite in making this method public so that we could use it in our RequestFactory?

    Enhancement 
    opened by markstory 4
  • Fix `symfony/error-handler` deprecations

    Fix `symfony/error-handler` deprecations

    | Q | A |-------------- | ------ | Documentation | no | Bugfix | yes (?) | BC Break | no | New Feature | no | RFC | no | QA | no

    Description

    symfony/error-handler triggers deprecation errors in case of not (explicitly) specified return types when implemented interface have them declared (in phpdoc). AFAIK they are triggered to make libraries migration to (possible) future declared return types more explicit.

    It can be annoying to update all of libraries with such of changes, but these deprecation messages are pretty hard to silence :(

    Here's log of there errors:

    PHP Deprecated: Method "Psr\Http\Message\ServerRequestInterface::getParsedBody()" might add "array|object|null" as a native return type declaration in the future. Do the same in implementation "Laminas\Diactoros\ServerRequest" now to avoid errors or add an explicit @return annotation to suppress this message. in .../vendor/symfony/error-handler/DebugClassLoader.php on line 330
    PHP Deprecated: Method "Psr\Http\Message\ServerRequestInterface::getAttribute()" might add "mixed" as a native return type declaration in the future. Do the same in implementation "Laminas\Diactoros\ServerRequest" now to avoid errors or add an explicit @return annotation to suppress this message. in .../vendor/symfony/error-handler/DebugClassLoader.php on line 330
    PHP Deprecated: Method "Psr\Http\Message\StreamInterface::getMetadata()" might add "mixed" as a native return type declaration in the future. Do the same in implementation "Laminas\Diactoros\Stream" now to avoid errors or add an explicit @return annotation to suppress this message. in .../vendor/symfony/error-handler/DebugClassLoader.php on line 330
    
    opened by andrew-demb 4
  • Update to `laminas/laminas-coding-standard:2.3.x`, improved types and internal API

    Update to `laminas/laminas-coding-standard:2.3.x`, improved types and internal API

    | Q | A |-------------- | ------ | QA | yes

    Description

    Does the donkey work upgrading to LCS 2.3

    Changes to tests and src are in separate commits

    Enhancement 
    opened by gsteel 4
  • Ignore obviously malformed `host` headers when constructing a ServerRequest

    Ignore obviously malformed `host` headers when constructing a ServerRequest

    | Q | A |-------------- | ------ | Documentation | no | Bugfix | no | BC Break | no | New Feature | yes | RFC | no | QA | no

    Description

    The comment within the code should be self-explanatory. This adds some very basic checks to the host header as a hardening measure.

    Enhancement 
    opened by TimWolla 4
  • Normalize line-folded headers values to not contain newlines

    Normalize line-folded headers values to not contain newlines

    | Q | A |-------------- | ------ | Documentation | no | Bugfix | yes | BC Break | maybe? | New Feature | no | RFC | no | QA | no

    Description

    As per RFC 7230#3.2.4:

    A server that receives an obs-fold in a request message that is not within a message/http container MUST […] replace each received obs-fold with one or more SP octets prior to interpreting the field value or forwarding the message downstream. […] A user agent that receives an obs-fold in a response message that is not within a message/http container MUST replace each received obs-fold with one or more SP octets prior to interpreting the field value.

    Furthermore this change improves interoperability with PSR-7 implementations that reject line folding.

    The updated behavior matches the suggested behavior with regard to the handling of line-folding in the new php-fig/fig-standards#1274 erratum.

    Bug Enhancement 
    opened by TimWolla 4
  • Support for web servers that send HTTP2 request protocol as HTTP/2.0. Fixes #71

    Support for web servers that send HTTP2 request protocol as HTTP/2.0. Fixes #71

    | Q | A |-------------- | ------ | Documentation |no | Bugfix | yes | BC Break |no | New Feature |no | RFC |no | QA |no

    Description

    Fixes #71

    Enhancement 
    opened by JakeBooher 4
  • Add test to detect regression described in #111

    Add test to detect regression described in #111

    Signed-off-by: Denis Ponomarev [email protected]

    | Q | A |-------------- | ------ | Documentation | no | Bugfix | no | BC Break | no | New Feature |no | RFC | no | QA | yes

    Description

    FilterUsingXForwardedHeaders should accept host:port pair in X-FORWARDED-HOST header.

    Test added to detect it parsed incorrectly.

    Awaiting Maintainer Response Bug 
    opened by 3DFace 6
  • `FilterUsingXForwardedHeaders` should correctly deal with `<host>:<port>` pair in `X-FORWARDED-HOST` header

    `FilterUsingXForwardedHeaders` should correctly deal with `:` pair in `X-FORWARDED-HOST` header

    Hello contributors!

    I get from my web-server headers like:

    X-FORWARDED-HOST = host:port 
    X-FORWARDED-PORT = port
    

    I am using FilterUsingXForwardedHeaders filter and in result I get wierd URI from ServerRequestFactory::fromGlobals with port duplicated like https://host:port:port/path.

    I guessX-FORWARDED-HOST in FilterUsingXForwardedHeaders should be parsed in the same way like ServerRequestFactory::marshalHostAndPortFromHeader() did.

    In earlier versions (updated 2.9.2 -> 2.13.0) it was working fine. So it's a kind of little BC Break too :)

    I understand that I can implement FilterServerRequestInterface myself, but it would be more convenient to have such feature out of the box.

    Thank you!

    Bug Unit Test Needed 
    opened by 3DFace 4
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    Awaiting Schedule

    These updates are awaiting their schedule. Click on a checkbox to get an update now.

    • [ ] Lock file maintenance

    Detected dependencies

    composer
    composer.json
    • php ~8.0.0 || ~8.1.0 || ~8.2.0
    • psr/http-factory ^1.0
    • psr/http-message ^1.0
    • http-interop/http-factory-tests ^0.9.0
    • laminas/laminas-coding-standard ^2.4.0
    • php-http/psr7-integration-tests ^1.2
    • phpunit/phpunit ^9.5.27
    • psalm/plugin-phpunit ^0.18.4
    • vimeo/psalm ^5.4
    github-actions
    .github/workflows/continuous-integration.yml
    .github/workflows/docs-build.yml
    .github/workflows/release-on-milestone-closed.yml

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    renovate 
    opened by renovate[bot] 0
  • Allow double slashes in the path according to the RFC3986

    Allow double slashes in the path according to the RFC3986

    | Q | A |-------------- | ------ | Documentation | no | Bugfix | yes | BC Break | maybe | New Feature | no | RFC | no | QA | no

    Description

    This resolves #74 maybe it could be a BC break, because the behavior of the getPath has changed. its since this commit: https://github.com/laminas/laminas-diactoros/commit/68fc7424a66735926589dbaf74c0659c09e75764

    Awaiting Maintainer Response BC Break Enhancement 
    opened by marcelthole 7
  • Low performance of TextResponse and another related responses

    Low performance of TextResponse and another related responses

    Feature Request

    | Q | A |------------ | ------ | New Feature | no | RFC | no | BC Break | no

    Summary

    Currently TextResponse always allocating new buffer for string output - https://github.com/laminas/laminas-diactoros/blob/2.6.x/src/Response/TextResponse.php#L75 This approach working really slow, my suggestion is to implement pure RAM string stream. Here is what I mean - https://github.com/makise-co/framework/blob/master/src/Http/FakeStream.php (this approach is ~30% more performant)

    Enhancement 
    opened by codercms 11
  • Stream is not fully compatible with GD resource

    Stream is not fully compatible with GD resource

    Bug Report

    | Q | A |------------ | ------ | Version(s) | 2.4.0

    Summary

    Using a GD resource works fine until there is interaction with the stream.

    Current behavior

    When working with GD Images, most of the methods of the Stream (with PHP 8.0 its GDImage) will result in errors.

    How to reproduce

        public function testIsReableWithGdResource()
        {
            $resource = imagecreate(1, 1);
            $stream   = new Stream($resource);
            $this->assertTrue($stream->isReadable());
        }
    
        public function testCloseWithGdResource()
        {
            $resource = imagecreate(1, 1);
            $stream   = new Stream($resource);
            $this->assertNull($stream->close());
        }
    
    

    result in

    1) LaminasTest\Diactoros\StreamTest::testIsReableWithGdResource
    stream_get_meta_data(): supplied resource is not a valid stream resource
    
    2) LaminasTest\Diactoros\StreamTest::testCloseWithGdResource
    fclose(): supplied resource is not a valid stream resource
    

    So the existing code is already broken and doesn't work with image resources.

    Expected behavior

    Using methods return proper informations such as the GD Image/Resource is not writable, seekable, e.g.

    Originally posted by @ADmad in https://github.com/laminas/laminas-diactoros/pull/46#r516719793

    Bug Question 
    opened by boesing 16
Releases(2.24.0)
Owner
Laminas Project
Laminas components and MVC.
Laminas Project
PSR-7 HTTP Message implementation

zend-diactoros Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-diactoros. Master: Develop: Diactoros (pronunciation: /dɪʌ

Zend Framework 1.6k Dec 9, 2022
HTTP header kit for PHP 7.1+ (incl. PHP 8) based on PSR-7

HTTP header kit for PHP 7.1+ (incl. PHP 8) based on PSR-7 Installation composer require sunrise/http-header-kit How to use? HTTP Header Collection Mor

Sunrise // PHP 63 Dec 31, 2022
Simple HTTP cURL client for PHP 7.1+ based on PSR-18

Simple HTTP cURL client for PHP 7.1+ based on PSR-18 Installation composer require sunrise/http-client-curl QuickStart composer require sunrise/http-f

Sunrise // PHP 15 Sep 5, 2022
Declarative HTTP Clients using Guzzle HTTP Library and PHP 8 Attributes

Waffler How to install? $ composer require waffler/waffler This package requires PHP 8 or above. How to test? $ composer phpunit Quick start For our e

Waffler 3 Aug 26, 2022
A super lightweight PSR-7 implementation

PSR-7 implementation A super lightweight PSR-7 implementation. Very strict and very fast. Description Guzzle Laminas Slim Nyholm Lines of code 3.300 3

Tobias Nyholm 972 Jan 5, 2023
Guzzle, an extensible PHP HTTP client

Guzzle, PHP HTTP client Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interf

Guzzle 22.3k Jan 2, 2023
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022
A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.

Httpful Httpful is a simple Http Client library for PHP 7.2+. There is an emphasis of readability, simplicity, and flexibility – basically provide the

Nate Good 1.7k Dec 21, 2022
PHP's lightweight HTTP client

Buzz - Scripted HTTP browser Buzz is a lightweight (<1000 lines of code) PHP 7.1 library for issuing HTTP requests. The library includes three clients

Kris Wallsmith 1.9k Jan 4, 2023
HTTPlug, the HTTP client abstraction for PHP

HTTPlug HTTPlug, the HTTP client abstraction for PHP. Intro HTTP client standard built on PSR-7 HTTP messages. The HTTPlug client interface is compati

The PHP HTTP group 2.4k Dec 30, 2022
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

This is a port of the VCR Ruby library to PHP. Record your test suite's HTTP interactions and replay them during future test runs for fast, determinis

php-vcr 1.1k Dec 23, 2022
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022
The HttpClient component provides powerful methods to fetch HTTP resources synchronously or asynchronously.

HttpClient component The HttpClient component provides powerful methods to fetch HTTP resources synchronously or asynchronously. Resources Documentati

Symfony 1.7k Jan 6, 2023
Unirest in PHP: Simplified, lightweight HTTP client library.

Unirest for PHP Unirest is a set of lightweight HTTP libraries available in multiple languages, built and maintained by Mashape, who also maintain the

Kong 1.3k Dec 28, 2022
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs

PHP Curl Class: HTTP requests made easy PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs. Installation Requirements Quic

null 3.1k Jan 5, 2023
The HttpFoundation component defines an object-oriented layer for the HTTP specification.

HttpFoundation Component The HttpFoundation component defines an object-oriented layer for the HTTP specification. Resources Documentation Contributin

Symfony 8.3k Dec 29, 2022
↪️ Bypass for PHP creates a custom HTTP Server to return predefined responses to client requests

Bypass for PHP provides a quick way to create a custom HTTP Server to return predefined responses to client requests.Useful for tests with Pest PHP or PHPUnit.

CiaReis 101 Dec 1, 2022
Application for logging HTTP and DNS Requests

Request Logger Made by Adam Langley ( https://twitter.com/adamtlangley ) What is it? Request logger is a free and open source utility for logging HTTP

null 13 Nov 28, 2022
TusPHP - 🚀a HTTP based protocol for resumable file uploads.

tus is a HTTP based protocol for resumable file uploads. Resumable means you can carry on where you left off without re-uploading whole data again in case of any interruptions. An interruption may happen willingly if the user wants to pause, or by accident in case of a network issue or server outage.

Ankit Pokhrel 1.3k Dec 28, 2022