Provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests

Related tags

HTTP http
Overview

laminas-http

🇷🇺 Русским гражданам

Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.

У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.

Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"

🇺🇸 To Citizens of Russia

We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.

One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.

You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"

This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering Committee. If you have a security issue, please follow our security reporting guidelines. If you wish to take on the role of maintainer, please nominate yourself

You can continue using laminas/laminas-http safely. Its successor will be PSR-7 in a later revision of laminas/laminas-mvc.

Build Status Coverage Status

laminas-http provides the HTTP message abstraction used by laminas-mvc, and also provides an extensible, adapter-driven HTTP client library.

This library does not support PSR-7, as it predates that specification. For PSR-7 support, please see our Diactoros component.

Installation

Run the following to install this library:

$ composer require laminas/laminas-http

Documentation

Browse the documentation online at https://docs.laminas.dev/laminas-http/

Support

Comments
  • Promote HTTP Headers as standalone component

    Promote HTTP Headers as standalone component

    Currently there is a lack of HTTP header builder / parser in the PHP community ecosystem.

    I suggest move Zend\Http\Header namespace to an standalone component for better reusability.

    Actually zendframework/zend-http installs 6 packages, 4 direct dependencies + 2 indirect dependencies.

    The proposed roadmap is move the subcomponent files to the new repository under the Composer's name of zendframework/zend-http-headers and make it a requirement of zendframework/zend-http

    The following files are excluded from these movement and should be keep in this repo.

    • HeaderLoader A Zend\Loader plugin loader of header files.
    • Headers A headers collection which is not reusable for PSR-7 interfaces

    BC Breaks: Generally speaking there is no BC Breaks but Header exceptions won't inherit from Zend\Header\Exception anymore


    Originally posted by @Maks3w at https://github.com/zendframework/zend-http/issues/43

    Awaiting Maintainer Response Enhancement Question 
    opened by weierophinney 9
  • Zend\Uri\Exception\InvalidUriPartException: Host

    Zend\Uri\Exception\InvalidUriPartException: Host "[IP ADDRESS]" is not valid or is not accepted by Zend\Uri\Http

    Bug Report

    | Q | A |------------ | ------ | Version(s) | ^2.7

    Summary

    Laminas\Uri\Exception\InvalidUriPartException: Host "[IP ADDRESS]" is not valid or is not accepted by Laminas\Uri\Http

    Current behavior

    When certain requests are made a 500 server error is produced.

    This appears to be happening on AWS servers hosting zend framework see:

    https://magento.stackexchange.com/questions/299596/getting-error-php-fatal-error-uncaught-zend-uri-exception-invaliduripartexcept

    https://serverfault.com/questions/996647/getting-error-php-fatal-error-uncaught-zend-uri-exception-invaliduripartexcept

    We are also experiencing the error on our Zend Framework site when a set of requests are being sent from an AWS Security Scanner:

    44.225.84.206 - - [10/Mar/2020:13:27:06 +0000] "GET http://[::ffff:a9fe:a9fe]/ HTTP/1.1" 500 - "-" "AWS Security Scanner"

    The problem is with these lines of code starting on line 298 in /src/PhpEnvironment/Request.php

                // Check for missinterpreted IPv6-Address
                // Reported at least for Safari on Windows
                if (isset($this->serverParams['SERVER_ADDR']) && preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
                    $host = '[' . $this->serverParams['SERVER_ADDR'] . ']';
                    if ($port . ']' == substr($host, strrpos($host, ':') + 1)) {
                        // The last digit of the IPv6-Address has been taken as port
                        // Unset the port so the default port can be used
                        $port = null;
                    }
                }
    

    How to reproduce

    <?php
    
    use PHPUnit\Framework\TestCase;
    //use Zend\Http\PhpEnvironment\Request;
    use \Laminas\Http\PhpEnvironment\Request;
    
    class Test extends TestCase
    {
        public function testInvalidHost()
        {
            $_SERVER = [
                'SCRIPT_NAME'           => '',
                'SERVER_ADDR'           => '10.0.33.135',
                'SERVER_NAME'           => '[::ffff:a9fe:a9fe]',
           ];
            $request = new Request();
    
        }
    
    }
    

    Expected behavior

    The host should be null, 10.0.33.135, or [::ffff:a9fe:a9fe] not [10.0.33.135]

    Bug 
    opened by parkbot 7
  • ChunkedBody decoding with Curl Adapter

    ChunkedBody decoding with Curl Adapter

    Zend\Http\Response::decodeChunkedBody fail with exception when curl adapter decode body itself , BUT it still has "Transfer-Encoding: encoded" header

    $client = new \Zend\Http\Client();
    $client->setOptions(array( 
       'sslverifypeer' => false,
       'adapter'         => 'Zend\Http\Client\Adapter\Curl',
    ));
    $client->setUri('https://www.truesocialmetrics.com/');
    $response = $client->send(); // Error parsing body - doesn't seem to be a chunked message
    

    php: 5.5 , 5.6, 7


    Originally posted by @necromant2005 at https://github.com/zendframework/zend-http/issues/19

    opened by weierophinney 7
  • Https request validation

    Https request validation

    Hi ZF team! Just a little thing:

    How can I check if the request scheme is https? Regardless the getScheme() method, does the Request class has a method for that? I can get the scheme:

    $request = $this->request->getUri();
    return ($request->getScheme() === 'https');
    

    So, where should I add this validation for make it available for all controllers? Anyways, would be great add this method on the Request object.

    $this->request->isSecure() 
    // or maybe
    $this->request->isHttps()
    

    Thanks! great project :1st_place_medal:


    Originally posted by @diemax at https://github.com/zendframework/zend-http/issues/123

    opened by weierophinney 7
  • Fix content deflating for IIS HTTP responses

    Fix content deflating for IIS HTTP responses

    | Q | A |-------------- | ------ | Bugfix | yes | BC Break | no

    Description

    Some response coming from IIS are using gzuncompress instead of gzinflate.

    Note: This fix was already fixed 10 years ago on ZF1 https://github.com/zendframework/zf1/commit/1e158aa35ff672564a74636c140ebc8309d6ed07 but this this was not ported in ZF2. See: https://framework.zend.com/issues/browse/ZF-12457.html

    To reproduce:

    use Laminas\Http\Client;
    $client = new Client('https://www.vnews.com/With-Federal-Money-Running-Out-Lebanon-Starts-to-Pick-Up-Motel-Tabs-for-Homeless-48667855');
    echo $client->send()->getBody();
    

    Current result:

    PHP Warning: gzuncompress(): data error in vendor/laminas/laminas-http/src/Response.php on line 653
    
    Bug 
    opened by blat 6
  • Changed default beauvoir for HTTP Version

    Changed default beauvoir for HTTP Version

    BC Break Report

    | Q | A |------------ | ------ | Version | 2.15.0

    Summary

    After upgrading from Verion 2.14.3 to Version 2.15.0 I could record that requests are sent with HTTP 1.0 instead of HTTP 1.1.

    The default HTTP version is set to the const value of \Laminas\Http\Request::VERSION_11 wich is the string '1.1'. see \Laminas\Http\Client::$config

         'httpversion'     => Request::VERSION_11,
    

    The Curl Adapter compares this string to the float value 1.1 in a typesafe way and will switch the HTTP version to 1.0. see \Laminas\Http\Client\Adapter\Curl line 445

    $curlHttp = $httpVersion === 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
    

    Previous behavior

    Requests sended by default with HTTP version 1.1 with the Curl adapter

    Current behavior

    Requests sended by default with HTTP version 1.0 with the Curl adapter

    How to reproduce

    Some Code:

    <?php
    
    require_once 'vendor/autoload.php';
    
    class CurlWrapper extends \Laminas\Http\Client\Adapter\Curl
    {
        public function write($method, $uri, $httpVersion = 1.1, $headers = [], $body = '')
        {
            $result = parent::write($method, $uri, $httpVersion, $headers, $body);
    
            preg_match(
                '/^.*HTTP\/(.*)\s$/m',
                $result,
                $matches
            );
    
            // Should be by default 1.1
            $realHttpVersion = $matches[1];
    
            // $httpVersion is actually a mixed type
            if ($httpVersion == 1.1 && $realHttpVersion != $httpVersion) {
                throw new \LogicException('Unexpected HTTP version sent');
            }
    
            return $result;
        }
    
    }
    
    $clientDefault = new \Laminas\Http\Client(
        'http://jsonplaceholder.typicode.com/todos/1',
        [
            'adapter' => CurlWrapper::class,
        ]
    );
    $clientDefault->send(); // throws the "Unexpected HTTP version sent" exception
    
    $clientOverwrittenByConst = new \Laminas\Http\Client(
        'http://jsonplaceholder.typicode.com/todos/1',
        [
            'adapter' => CurlWrapper::class,
            'httpversion' => \Laminas\Http\Request::VERSION_11
        ]
    );
    $clientOverwrittenByConst->send(); // throws the "Unexpected HTTP version sent" exception
    
    $clientOverwrittenByFloat = new \Laminas\Http\Client(
        'http://jsonplaceholder.typicode.com/todos/1',
        [
            'adapter' => CurlWrapper::class,
            'httpversion' => 1.1
        ]
    );
    $clientOverwrittenByFloat->send(); // correct behaviour
    
    BC Break Bug 
    opened by MOuli90 6
  • invalid date in response header

    invalid date in response header

    Shouldn't that be catched?

    [Zend\Http\Header\Exception\InvalidArgumentException]
    Invalid date passed as string (0)
    
    [Exception]
    DateTime::__construct(): Failed to parse time string(0) at position 0 (0): Unexcepted character
    

    Originally posted by @aight8 at https://github.com/zendframework/zend-http/issues/9

    Awaiting Author Updates 
    opened by weierophinney 6
  • Allows `require-trusted-types-for` CSP directive

    Allows `require-trusted-types-for` CSP directive

    | Q | A |-------------- | ------ | Bugfix | yes | BC Break | no

    Description

    When headers contain require-trusted-types-for CSP directive, Headers::toArray ends with a PHP Fatal Error.

    To reproduce:

    use Laminas\Http\Client;
    $client = new Client('http://news.google.com/news?ned=us&topic=t&output=atom');
    $client->send()->getHeaders()->toArray();
    

    Current result:

    PHP Fatal error: Uncaught Error: [] operator not supported for strings in vendor/laminas/laminas-http/src/Headers.php:456
    
    Bug 
    opened by blat 5
  • Fixes #5 : Handle Response::sendHeaders() to not silently returns when header already sent

    Fixes #5 : Handle Response::sendHeaders() to not silently returns when header already sent

    Signed-off-by: Abdul Malik Ikhsan [email protected]

    | Q | A |-------------- | ------ | BC Break | yes

    Description

    Fixes https://github.com/laminas/laminas-http/issues/5 Handle Response::sendHeaders() to not silently returns when header already sent

    Bug Enhancement 
    opened by samsonasik 5
  • http_build_query should specify arg separator

    http_build_query should specify arg separator

    In http client zendframework/zend-http/src/Client.php:1231 $body request is created using http_build_query function.

    $body = http_build_query($this->getRequest()->getPost()->toArray());

    Problem is that separator can be changed via ini_set('arg_separator.output', 'some other'); and this will break http client. Since "x-www-form-urlencoded" accepts only "&" as a separator, suggest to hardcode it there.

    See similar issue: https://www.drupal.org/node/2372211


    Originally posted by @ameoba32 at https://github.com/zendframework/zend-http/issues/33

    opened by weierophinney 5
  • About the ssltransport option for the Socket client

    About the ssltransport option for the Socket client

    We currently accept these values for the ssltransport option of the Socket client:

    • sslSTREAM_CRYPTO_METHOD_SSLv23_CLIENT
    • sslv2STREAM_CRYPTO_METHOD_SSLv2_CLIENT
    • sslv3STREAM_CRYPTO_METHOD_SSLv3_CLIENT
    • tlsSTREAM_CRYPTO_METHOD_TLS_CLIENT

    In particular:

    • STREAM_CRYPTO_METHOD_SSLv23_CLIENT
      • evaluates to SSLv2 / SSLv3 for 5.5.0 ≤ PHP ≤ 5.6.6 (reference)
      • evaluates to TLSv1.0 / TLSv1.1 / TLSv1.2 for 5.6.7 ≤ PHP ≤ 7.1.0 (reference)
    • STREAM_CRYPTO_METHOD_TLS_CLIENT
      • evaluates to TLSv1.0 / TLSv1.1 / TLSv1.2 for 5.6.0 ≤ PHP ≤ 5.6.6
      • evaluates to TLSv1.0 for 5.6.7 ≤ PHP ≤ 7.1.0

    There are some problems with the current implementation:

    • the constant values change between different PHP versions, and that leads to portability problems
    • we allow specifying the version of SSL, but not the version of TLS
    • we don't have a way to allow any protocol (aka the STREAM_CRYPTO_METHOD_ANY_CLIENT option introduced in PHP 5.6.0, which evaluates to SSLv2 / SSLv3 / TLSv1.0 / TLSv1.1 / TLSv1.2)

    So, what about defining the following transports?

    • ssl to enable sslv2 and sslv3
    • sslv2 to enable only sslv2
    • sslv3 to enable only sslv3
    • tls to enable tlsv1.0 and tlsv1.1 and tlsv1.2
    • tlsv1.0 to enable only tlsv1.0
    • tlsv1.1 to enable only tlsv1.1
    • tlsv1.2 to enable only tlsv1.2
    • * to enable any kind of connections

    Furthermore, because of security issues, more and more websites disable SSL (both SSLv2 and SSLv3), keeping only TLS connections (see for instance what's doing Google).

    So, what about switching from ssl to tls as the default transport?


    Originally posted by @mlocati at https://github.com/zendframework/zend-http/issues/105

    opened by weierophinney 5
Releases(2.18.0)
Owner
Laminas Project
Laminas components and MVC.
Laminas Project
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
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
A simple PHP Toolkit to parallel generate combinations, save and use the generated terms to brute force attack via the http protocol.

Brutal A simple PHP Toolkit to parallel generate combinations, save and use the generated terms to apply brute force attack via the http protocol. Bru

Jean Carlo de Souza 4 Jul 28, 2021
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
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
↪️ 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
librestful is a virion for PocketMine servers that make easier, readable code and for async http requests.

librestful is a virion for PocketMine servers that make easier, readable code for async rest requests.

RedMC Network 17 Oct 31, 2022
🐼 Framework agnostic package using asynchronous HTTP requests and PHP generators to load paginated items of JSON APIs into Laravel lazy collections.

Framework agnostic package using asynchronous HTTP requests and generators to load paginated items of JSON APIs into Laravel lazy collections.

Andrea Marco Sartori 61 Dec 3, 2022
Requests - a HTTP library written in PHP, for human beings

Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python library. Requests is ISC Licensed (similar to the new BSD license) and has no dependencies, except for PHP 5.6+.

WordPress 3.5k Jan 6, 2023
PHP Curl - This package can send HTTP requests to a given site using Curl.

PHP Curl This package can send HTTP requests to a given site using Curl. It provides functions that can take several types of parameters to configure

Mehmet Can 1 Oct 27, 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
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
This package provides the database factory experience to fake Http calls in your testsuite.

This package provides the database factory experience to fake Http calls in your testsuite

DIJ 11 May 2, 2022
Zenscrape package is a simple PHP HTTP client-provider that makes it easy to parsing site-pages

Zenscrape package is a simple PHP HTTP client-provider that makes it easy to parsing site-pages

Andrei 3 Jan 17, 2022
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
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