Amphp Http Server Versions Save

An advanced async HTTP server library for PHP, perfect for real-time apps and APIs with high concurrency demands.

v2.1.0

3 years ago
  • Added CallableMiddleware (#313)
  • Improved exception logging (#306)
  • Added setting to Options to pass the Request object to the logger context. The option defaults to off. (#310)
  • Fixed HTTP/2 streams closing if the response was sent before the request body was fully received. (#304)
  • Fixed HTTP/2 window size for too large request bodies, so they can be rejected instead of hanging

v2.0.1

4 years ago
  • Fixed HTTP/2 window size validation on 32 bit platforms

v2.0.0

4 years ago

This release provides compatibility with amphp/socket v1.0. Please see the amphp/socket release notes for more information on changes in that library. While most code using this library should not require major changes, some compatibility breaks with v1.x were made.

Summary of compatibility breaks from v1.x to v2.0

  • Updated to league/uri@^6. Consequentially, PHP 7.2+ is now required.
  • Renamed Server to HttpServer. An alias of Server to HttpServer was kept for backward compatibility with v1.x, but may be removed in a future version.
  • Added Push object for pushed resources. Response::getPush() now returns an array of Push objects.
  • Upgrade callbacks (those set with Response::upgrade()) now receive an instance of Amp\Socket\EncryptableSocket, an interface extending Amp\Socket\Socket, as the parameter to the callback function. Upgrade callback are now run as a coroutine if a generater is returned. Coroutine (or promise returned from the callback) failures are logged to the server log.
  • Driver\Client returns an instance of Amp\Socket\SocketAddress from getLocalAddress() and getRemoteAddress(). The methods getLocalPort() and getRemotePort() have been removed. The IP address and port are available on the instance of SocketAddress returned.
  • Driver\Client::getCryptoContext() has been replaced with getTlsInfo(), which now returns an instance of Amp\Socket\TlsInfo for encrypted clients or null for plaintext clients.
  • HTTP/2 protocol is now declared as "2" instead of "2.0" in requests and responses (see https://http2.github.io/faq/#is-it-http20-or-http2).
  • Refactored HTTP/2 flood prevention to be based on a ratio between payload and non-payload bytes received, inspired by NGINX's flood prevention. Some options were removed:
    • Removed Options::getMinimumAverageFrameSize() and withMinimumAverageFrameSize().
    • Removed Options::getFramesPerSecondLimit() and withFramesPerSecondLimit().
  • Removed Options::getConnectionTimeout() and withConnectionTimeout(). HTTP/1.x and HTTP/2 connection timeouts are now separate and can be set using the http1Timeout (default 15 seconds) and http2Timeout (default 60 seconds) options.

Trailers

The Trailers object has been refactored to contain a list of header declared trailer fields (which may be empty) and a promise for an Amp\Http\Message object containing the future trailer values. Trailers in requests have been moved from the request body to the Request object. Request::getTrailers() returns a Trailers object having two methods:

  • Trailers::getFields(): Returns an array of declared trailer fields (this list may be empty, but still receive trailers).
  • Trailers::await(): Returns a promise that is resolved with a Amp\Http\Message instance once all trailers have been received.

Trailers are now supported in responses. A new Response constructor parameter or Response::setTrailers(Trailers $trailers) may be used to set a Trailers object for the response. The promise provided to the Trailers constructor should be resolved with an array of header values indexed by the header field name, similar to header field array provided to the Response constructor or Response::setHeaders().

Other backward compatibility breaks unlikely to affect application code

  • Driver\Http1Driver and Driver\Http2Driver constructors now require an instance of Psr\Log\LoggerInterface as the final parameter.
  • Promise parameter for Trailers object removed from RequestBody constructor.
  • void returns added to start(), onClose(), and close() methods in Driver\Client interface.
  • void return added to TimeReference::onTimeUpdate().
  • HTTP/2 pseudo headers (header fields starting with a colon (:) such as :method or :status) cannot be used in Request and Response. Accordingly, these header fields are no longer included in requests generated by the server. The values of these headers are used to populate request properties and should be accessed by getters in Request.
  • Removed TimeReference and SystemTimeReference. Use Amp\Http\formatDateHeader() in the amphp/[email protected] package to generate the value for an HTTP header value containing a date.
  • Refactored TimeoutCache and renamed some methods. Client timeouts are no longer updated within Client, rather HttpDriver implementations must update the client timeout. Users should be unaffected by this change unless they implemented their own Client or HttpDriver.
  • HttpDriverFactory::selectDriver() now requires instances of ErrorHandler, Psr\Log\LoggerInterface, and Options in addition to the Client instance.

New Features

  • The original casing of HTTP/1.x request headers is now available through Request::getRawHeaders().
  • Added Request::getAttributes() to retrieve an array of all request attributes and Request::removeAttribute() to remove an attribute.
  • Added Request::removeAttribute().
  • Added ClientException::getClient() that returns the Client that caused the error.
  • Back-pressure from consumption of request bodies is now used to control window sizes in HTTP/2. Window sizes are only increased in small increments instead of the entire allowable body size. This will improve memory consumption when handling large request bodies.
  • Added tlsSetupTimeout in Options. Default is 5 seconds.

Upgrading from v1.x

We believe only minor changes will be necessary for applications to upgrade from v1.x to v2.0. As trailers and upgrade responses are uncommon for applications, the most likely concern for upgraders is the shift to SocketAddress in Client::getLocalAddress() and Client::getRemoteAddress(), changes to methods in Options, as well as the changes made in amphp/socket v1.0.

v1.1.3

4 years ago
  • Fixed a bug in calculating remaining chunk length in HTTP/1.x chunked request body parsing (#292)

v2.0.0-rc4

4 years ago
  • Http2Driver now uses an HTTP/2 parser shared with amphp/http-client. Removed Http2Exception and child classes, which have been replaced by exception classes in amphp/http.
  • Upgraded to amphp/hpack @ ^3.
  • Renamed Request::getPush() to getPushes().

v2.0.0-rc3

4 years ago
  • Updated to league/uri@^6. Consequentially, PHP 7.2+ is now required.
  • Renamed Server to HttpServer. An alias of Server to HttpServer was kept for backward compatibility with v1.x, but may be removed in a future version.
  • Added Push object for pushed resources. Response::getPush() now returns an array of Push objects.
  • Restored Client::isUnix() method.
  • Added ClientException::getClient() that returns the Client that caused the error.
  • Renamed Trailers::awaitMessage() to await().
  • Added Request::removeAttribute().
  • Back-pressure from consumption of request bodies is now used to control window sizes in HTTP/2. Window sizes are only increased in small increments instead of the entire allowable body size. This will improve memory consumption when handling large request bodies.
  • Refactored HTTP/2 flood prevention to be based on a ratio between payload and non-payload bytes received, inspired by NGINX's flood prevention. Some options were removed:
    • Removed Options::getMinimumAverageFrameSize() and withMinimumAverageFrameSize().
    • Removed Options::getFramesPerSecondLimit() and withFramesPerSecondLimit().
  • Removed Options::getConnectionTimeout() and withConnectionTimeout(). HTTP/1.x and HTTP/2 connection timeouts are now separate and can be set using the http1Timeout (default 15 seconds) and http2Timeout (default 60 seconds) options.
  • Added tlsSetupTimeout option. Default is 5 seconds.
  • Removed TimeReference and SystemTimeReference. Use Amp\Http\formatDateHeader() in the amphp/[email protected] package to generate the value for an HTTP header value containing a date.
  • Refactored TimeoutCache and renamed some methods. Client timeouts are no longer updated within Client, rather HttpDriver implementations must update the client timeout. Users should be unaffected by this change unless they implemented their own Client or HttpDriver.
  • HttpDriverFactory::selectDriver() now requires instances of ErrorHandler, Psr\Log\LoggerInterface, and Options in addition to the Client instance.

v2.0.0-rc2

4 years ago

Note: This is a pre-release, there might be breaking changes in the final stable version.

  • HTTP/2 protocol is now declared as "2" instead of "2.0" in requests and responses (see https://http2.github.io/faq/#is-it-http20-or-http2).
  • Added Request::getAttributes() to retrieve an array of all request attributes and Request::removeAttribute() to remove an attribute.

v2.0.0-rc1

4 years ago

This is the first release candidate of amphp/http-client v2.0.

Note: This is a pre-release, there might be breaking changes in the final stable version.

This release provides compatibility with amphp/socket v1.0. Please see the amphp/socket release notes for more information on changes in that library. Some minor compatibility breaks were required.

Summary of changes from v1.x to v2.0

  • Upgrade callbacks (those set with Response::upgrade()) now receive an instance of Amp\Socket\EncryptableSocket, an interface extending Amp\Socket\Socket, as the parameter to the callback function. Upgrade callback are now run as a coroutine if a generater is returned. Coroutine (or promise returned from the callback) failures are logged to the server log.
  • Driver\Client returns an instance of Amp\Socket\SocketAddress from getLocalAddress() and getRemoteAddress(). The methods getLocalPort() and getRemotePort() have been removed. The IP address and port are available on the instance of SocketAddress returned.
  • Driver\Client::getCryptoContext() has been replaced with getTlsInfo(), which now returns an instance of Amp\Socket\TlsInfo for encrypted clients or null for plaintext clients.
  • Driver\Client::isUnix() has been removed. Instead use getLocalAddress() and check for the return of SocketAddress::getPort() to be null.

Trailers

The Trailers object has been refactored to contain a list of header declared trailer fields (which may be empty) and a promise for an Amp\Http\Message object containing the future trailer values. Trailers in requests have been moved from the request body to the Request object. Request::getTrailers() returns a Trailers object having two methods:

  • getFields(): Returns an array of declared trailer fields (this list may be empty, but still receive trailers).
  • awaitMessage(): Returns a promise that is resolved with a Amp\Http\Message instance once all trailers have been received.

Trailers are now supported in responses. A new Response constructor parameter or Response::setTrailers(Trailers $trailers) may be used to set a Trailers object for the response. The promise provided to the Trailers constructor should be resolved with an array of header values indexed by the header field name, similar to header field array provided to the Response constructor or Response::setHeaders().

Other backward compatibility breaks unlikely to affect application code

  • Driver\Http1Driver and Driver\Http2Driver constructors now require an instance of Psr\Log\LoggerInterface as the final parameter.
  • Promise parameter for Trailers object removed from RequestBody constructor.
  • void returns added to start(), onClose(), and close() methods in Driver\Client interface.
  • void return added to TimeReference::onTimeUpdate().
  • HTTP/2 pseudo headers (header fields starting with a colon (:) such as :method or :status) cannot be used in Request and Response. Accordingly, these header fields are no longer included in requests generated by the server. The values of these headers are used to populate request properties and should be accessed by getters in Request.

Upgrading from v1.x

We believe only minor changes will be necessary for applications to upgrade from v1.x to v2.0. As trailers and upgrade responses are uncommon for applications, the most likely concern for upgraders is the shift to SocketAddress in Client::getLocalAddress() and Client::getRemoteAddress(), as well as the changes made in amphp/socket v1.0.

v1.1.2

4 years ago
  • Fixed sending HTTP/2 push promises with header blocks too large to fit into a single frame.

v1.1.1

4 years ago
  • Fixed cases where the HTTP/2 driver was not in conformance with the specification. Conformance is now checked automatically on each Travis build with h2spec. These fixes include (but are not limited to) the following:
    • Requests with unknown or duplicate pseudo-headers are now rejected.
    • Bodies not matching a given content-length header now fail with a ClientException.
    • Fix a bug in handling window updates resulting in a negative stream window.
    • Receiving any non-continuation frame between continuation frames rejects the request.
  • Requests with multiple content-length headers are now rejected (HTTP/1.x and HTTP/2).
  • Multiple transfer-encoding headers are now combined before being examined by the parser (generally resulting in a rejected request) (HTTP/1.x).