Skip to content

Releases: amphp/http-server

2.0.0 RC1

21 Aug 15:34
4d91b47
Compare
Choose a tag to compare
2.0.0 RC1 Pre-release
Pre-release

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.

1.1.2

20 Aug 17:36
a4936b0
Compare
Choose a tag to compare
  • Fixed sending HTTP/2 push promises with header blocks too large to fit into a single frame.

1.1.1

09 Aug 16:30
adec3f5
Compare
Choose a tag to compare
  • 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).

1.1.0

14 Jun 19:41
v1.1.0
Compare
Choose a tag to compare
  • Added redirectTo() and MovedResourceHandler for easier redirects.
  • Added ClientFactory to allow switching the client implementation.
  • Increased default HTTP/2 stream limits.
  • Improved body buffer handling.
  • Rethrow exceptions from onClose callbacks and execute them as coroutines.
  • Fixed connection timeout handling closing connections prematurely.

1.0.1

14 Jan 23:50
06e0095
Compare
Choose a tag to compare
  • Fixed handling of target for the CONNECT method.

1.0.0

10 Dec 19:38
v1.0.0
Compare
Choose a tag to compare

This library has been used on production for a long time already, but
we've never released v1.0.0, until now. Here it is, we're finally there.

There have been no changes between v0.8.3 and v1.0.0.

\o/

0.8.3

21 Sep 19:02
v0.8.3
Compare
Choose a tag to compare
  • Disabled compression if ext-zlib isn't available (#267)

0.8.2

07 Apr 20:40
76c516c
Compare
Choose a tag to compare
  • Fixed an issue when an HTTP/2 response is written immediately (#258).
  • Performance recommendations are now logged as warnings when starting the server depending the mode set in options (debug or production), the value of the zend.assertions ini setting, and if the xdebug extension is loaded (related to #256).
  • Request::setBody() and Response::setBody() now additionally accepts any value that can be cast to a string (such as integers, floats, and objects with a __toString() method) as the body content (#254).

0.8.1

25 Mar 16:53
Compare
Choose a tag to compare
  • Fixed an issue where latency was increased dramatically on some systems compared to v0.7.x (#252).
  • Fixed the content-length header being removed by CompressionMiddleware if the body was not long enough to be compressed.
  • ExceptionMiddleware now writes the exception to the log to mimic the default behavior if it were not used.

0.8.0

23 Mar 05:00
e68aab3
Compare
Choose a tag to compare

This version is a major refactor, with many components being moved to separate libraries.

A server is now created using an array of socket servers, an instance of RequestHandler, and a PSR-3 logger instance.

use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Server;
use Psr\Log\NullLogger;

Amp\Loop::run(function () {
    $sockets = [
        Amp\Socket\listen("0.0.0.0:1337"),
        Amp\Socket\listen("[::]:1337"),
    ];
    
    $server = new Server($sockets, new CallableRequestHandler(function (Request $request) {
        return new Response(Status::OK, [
            "content-type" => "text/plain; charset=utf-8"
        ], "Hello, World!");
    }), new NullLogger);

    yield $server->start();

    // Stop the server gracefully when SIGINT is received.
    // This is technically optional, but it is best to call Server::stop().
    Amp\Loop::onSignal(SIGINT, function (string $watcherId) use ($server) {
        Amp\Loop::cancel($watcherId);
        yield $server->stop();
    });
});

Request handling has been changed significantly. Requests are now handled through interfaces modeled after PSR-15, modified to be used in a non-blocking context.

Requests are handled by objects of classes implementing RequestHandler, which may be wrapped with any number of objects of classes implementing Middleware. Middleware is combined with a request handler using the Middleware\stack() function, returning an instance of RequestHandler that can be used with Server or anywhere else a RequestHandler may be used (such as routes in the routing library).

Please see the documentation for more information.