pax_global_header00006660000000000000000000000064136013537170014520gustar00rootroot0000000000000052 comment=72d2b129a48f0490d55b7f89be0d6aa0597ffb06 httplug-2.1.0/000077500000000000000000000000001360135371700132075ustar00rootroot00000000000000httplug-2.1.0/CHANGELOG.md000066400000000000000000000055311360135371700150240ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [2.1.0] - 2019-12-27 ### Changed - `Http\Client\Exception\NetworkException` no longer extends `Http\Client\Exception\RequestException`, in accordance with [PSR-18](https://www.php-fig.org/psr/psr-18/) ## [2.0.0] - 2018-10-31 This version is no BC break for consumers using HTTPlug. However, HTTP clients that implement HTTPlug need to adjust because we add return type declarations. ### Added - Support for PSR-18 (HTTP client). ### Changed - **BC Break:** `HttpClient::sendRequest(RequestInterface $request)` has a return type annotation. The new signature is `HttpClient::sendRequest(RequestInterface $request): ResponseInterface`. - **BC Break:** `RequestException::getRequest()` has a return type annotation. The new signature is `RequestException::getRequest(): RequestInterface`. ### Removed - PHP 5 support ## [1.1.0] - 2016-08-31 ### Added - HttpFulfilledPromise and HttpRejectedPromise which respect the HttpAsyncClient interface ## [1.0.0] - 2016-01-26 ### Removed - Stability configuration from composer ## [1.0.0-RC1] - 2016-01-12 ### Changed - Updated package files - Updated promise dependency to RC1 ## [1.0.0-beta] - 2015-12-17 ### Added - Puli configuration and binding types ### Changed - Exception concept ## [1.0.0-alpha3] - 2015-12-13 ### Changed - Async client does not throw exceptions ### Removed - Promise interface moved to its own repository: [php-http/promise](https://github.com/php-http/promise) ## [1.0.0-alpha2] - 2015-11-16 ### Added - Async client and Promise interface ## [1.0.0-alpha] - 2015-10-26 ### Added - Better domain exceptions. ### Changed - Purpose of the library: general HTTP CLient abstraction. ### Removed - Request options: they should be configured at construction time. - Multiple request sending: should be done asynchronously using Async Client. - `getName` method ## 0.1.0 - 2015-06-03 ### Added - Initial release [Unreleased]: https://github.com/php-http/httplug/compare/v2.0.0...HEAD [2.0.0]: https://github.com/php-http/httplug/compare/v1.1.0...HEAD [1.1.0]: https://github.com/php-http/httplug/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/php-http/httplug/compare/v1.0.0-RC1...v1.0.0 [1.0.0-RC1]: https://github.com/php-http/httplug/compare/v1.0.0-beta...v1.0.0-RC1 [1.0.0-beta]: https://github.com/php-http/httplug/compare/v1.0.0-alpha3...v1.0.0-beta [1.0.0-alpha3]: https://github.com/php-http/httplug/compare/v1.0.0-alpha2...v1.0.0-alpha3 [1.0.0-alpha2]: https://github.com/php-http/httplug/compare/v1.0.0-alpha...v1.0.0-alpha2 [1.0.0-alpha]: https://github.com/php-http/httplug/compare/v0.1.0...v1.0.0-alpha httplug-2.1.0/LICENSE000066400000000000000000000021541360135371700142160ustar00rootroot00000000000000Copyright (c) 2014 Eric GELOEN Copyright (c) 2015 PHP HTTP Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. httplug-2.1.0/README.md000066400000000000000000000050251360135371700144700ustar00rootroot00000000000000# HTTPlug [![Latest Version](https://img.shields.io/github/release/php-http/httplug.svg?style=flat-square)](https://github.com/php-http/httplug/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![Build Status](https://img.shields.io/travis/php-http/httplug/master.svg?style=flat-square)](https://travis-ci.org/php-http/httplug) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/httplug.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/httplug) [![Quality Score](https://img.shields.io/scrutinizer/g/php-http/httplug.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/httplug) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/httplug.svg?style=flat-square)](https://packagist.org/packages/php-http/httplug) [![Slack Status](http://slack.httplug.io/badge.svg)](http://slack.httplug.io) [![Email](https://img.shields.io/badge/email-team@httplug.io-blue.svg?style=flat-square)](mailto:team@httplug.io) **HTTPlug, the HTTP client abstraction for PHP.** ## Intro HTTP client standard built on [PSR-7](http://www.php-fig.org/psr/psr-7/) HTTP messages. The HTTPlug client interface is compatible with the official standard for the HTTP client interface, [PSR-18](http://www.php-fig.org/psr/psr-18/). HTTPlug adds an interface for asynchronous HTTP requests, which PSR-18 does not cover. Since HTTPlug has already been widely adopted and a whole ecosystem has been built around it, we will keep maintaining this package for the time being. HTTPlug 2.0 and newer extend the PSR-18 interface to allow for a convenient migration path. New client implementations and consumers should use the PSR-18 interfaces directly. In the long term, we expect PSR-18 to completely replace the need for HTTPlug. ## History HTTPlug is the official successor of the [ivory http adapter](https://github.com/egeloen/ivory-http-adapter). HTTPlug is a predecessor of [PSR-18](http://www.php-fig.org/psr/psr-18/) ## Install Via Composer ``` bash $ composer require php-http/httplug ``` ## Documentation Please see the [official documentation](http://docs.php-http.org). ## Testing ``` bash $ composer test ``` ## Contributing Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). ## Security If you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org). ## License The MIT License (MIT). Please see [License File](LICENSE) for more information. httplug-2.1.0/composer.json000066400000000000000000000020111360135371700157230ustar00rootroot00000000000000{ "name": "php-http/httplug", "description": "HTTPlug, the HTTP client abstraction for PHP", "license": "MIT", "keywords": ["http", "client"], "homepage": "http://httplug.io", "authors": [ { "name": "Eric GELOEN", "email": "geloen.eric@gmail.com" }, { "name": "Márk Sági-Kazár", "email": "mark.sagikazar@gmail.com" } ], "require": { "php": "^7.0", "psr/http-message": "^1.0", "psr/http-client": "^1.0", "php-http/promise": "^1.0" }, "require-dev": { "phpspec/phpspec": "^4.3.4|^5.0|^6.0", "friends-of-phpspec/phpspec-code-coverage" : "^4.1" }, "autoload": { "psr-4": { "Http\\Client\\": "src/" } }, "scripts": { "test": "vendor/bin/phpspec run", "test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml" }, "extra": { "branch-alias": { "dev-master": "2.x-dev" } } } httplug-2.1.0/puli.json000066400000000000000000000004251360135371700150540ustar00rootroot00000000000000{ "version": "1.0", "name": "php-http/httplug", "binding-types": { "Http\\Client\\HttpAsyncClient": { "description": "Async HTTP Client" }, "Http\\Client\\HttpClient": { "description": "HTTP Client" } } } httplug-2.1.0/src/000077500000000000000000000000001360135371700137765ustar00rootroot00000000000000httplug-2.1.0/src/Exception.php000066400000000000000000000004411360135371700164440ustar00rootroot00000000000000 */ interface Exception extends PsrClientException { } httplug-2.1.0/src/Exception/000077500000000000000000000000001360135371700157345ustar00rootroot00000000000000httplug-2.1.0/src/Exception/HttpException.php000066400000000000000000000033161360135371700212460ustar00rootroot00000000000000 */ class HttpException extends RequestException { /** * @var ResponseInterface */ protected $response; /** * @param string $message * @param RequestInterface $request * @param ResponseInterface $response * @param \Exception|null $previous */ public function __construct( $message, RequestInterface $request, ResponseInterface $response, \Exception $previous = null ) { parent::__construct($message, $request, $previous); $this->response = $response; $this->code = $response->getStatusCode(); } /** * Returns the response. * * @return ResponseInterface */ public function getResponse() { return $this->response; } /** * Factory method to create a new exception with a normalized error message. */ public static function create( RequestInterface $request, ResponseInterface $response, \Exception $previous = null ) { $message = sprintf( '[url] %s [http method] %s [status code] %s [reason phrase] %s', $request->getRequestTarget(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase() ); return new static($message, $request, $response, $previous); } } httplug-2.1.0/src/Exception/NetworkException.php000066400000000000000000000015111360135371700217530ustar00rootroot00000000000000 */ class NetworkException extends TransferException implements PsrNetworkException { use RequestAwareTrait; /** * @param string $message * @param RequestInterface $request * @param \Exception|null $previous */ public function __construct($message, RequestInterface $request, \Exception $previous = null) { $this->setRequest($request); parent::__construct($message, 0, $previous); } } httplug-2.1.0/src/Exception/RequestAwareTrait.php000066400000000000000000000006371360135371700220670ustar00rootroot00000000000000request = $request; } /** * {@inheritdoc} */ public function getRequest(): RequestInterface { return $this->request; } } httplug-2.1.0/src/Exception/RequestException.php000066400000000000000000000015561360135371700217630ustar00rootroot00000000000000 */ class RequestException extends TransferException implements PsrRequestException { use RequestAwareTrait; /** * @param string $message * @param RequestInterface $request * @param \Exception|null $previous */ public function __construct($message, RequestInterface $request, \Exception $previous = null) { $this->setRequest($request); parent::__construct($message, 0, $previous); } } httplug-2.1.0/src/Exception/TransferException.php000066400000000000000000000004071360135371700221110ustar00rootroot00000000000000 */ class TransferException extends \RuntimeException implements Exception { } httplug-2.1.0/src/HttpAsyncClient.php000066400000000000000000000012531360135371700175640ustar00rootroot00000000000000 */ interface HttpAsyncClient { /** * Sends a PSR-7 request in an asynchronous way. * * Exceptions related to processing the request are available from the returned Promise. * * @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception. * * @throws \Exception If processing the request is impossible (eg. bad configuration). */ public function sendAsyncRequest(RequestInterface $request); } httplug-2.1.0/src/HttpClient.php000066400000000000000000000004111360135371700165610ustar00rootroot00000000000000response = $response; } /** * {@inheritdoc} */ public function then(callable $onFulfilled = null, callable $onRejected = null) { if (null === $onFulfilled) { return $this; } try { return new self($onFulfilled($this->response)); } catch (Exception $e) { return new HttpRejectedPromise($e); } } /** * {@inheritdoc} */ public function getState() { return Promise::FULFILLED; } /** * {@inheritdoc} */ public function wait($unwrap = true) { if ($unwrap) { return $this->response; } } } httplug-2.1.0/src/Promise/HttpRejectedPromise.php000066400000000000000000000017671360135371700220640ustar00rootroot00000000000000exception = $exception; } /** * {@inheritdoc} */ public function then(callable $onFulfilled = null, callable $onRejected = null) { if (null === $onRejected) { return $this; } try { return new HttpFulfilledPromise($onRejected($this->exception)); } catch (Exception $e) { return new self($e); } } /** * {@inheritdoc} */ public function getState() { return Promise::REJECTED; } /** * {@inheritdoc} */ public function wait($unwrap = true) { if ($unwrap) { throw $this->exception; } } }