Skip to content

2.0.0 RC1

Pre-release
Pre-release
Compare
Choose a tag to compare
@trowski trowski released this 21 Aug 15:34
4d91b47

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.