v0.6.0
-
Feature / BC break: The
RequestandResponseobjects now follow strict
stream semantics and their respective methods and events.
(#116, #129, #133, #135, #136, #137, #138, #140, #141 by @legionth
and #122, #123, #130, #131, #132, #142 by @clue)This implies that the
Servernow supports proper detection of the request
message body stream, such as supporting decoding chunked transfer encoding,
delimiting requests with an explicitContent-Lengthheader
and those with an empty request message body.These streaming semantics are compatible with previous Stream v0.5, future
compatible with v0.5 and upcoming v0.6 versions and can be used like this:$http->on('request', function (Request $request, Response $response) { $contentLength = 0; $request->on('data', function ($data) use (&$contentLength) { $contentLength += strlen($data); }); $request->on('end', function () use ($response, &$contentLength){ $response->writeHead(200, array('Content-Type' => 'text/plain')); $response->end("The length of the submitted request body is: " . $contentLength); }); // an error occured // e.g. on invalid chunked encoded data or an unexpected 'end' event $request->on('error', function (\Exception $exception) use ($response, &$contentLength) { $response->writeHead(400, array('Content-Type' => 'text/plain')); $response->end("An error occured while reading at length: " . $contentLength); }); });
Similarly, the
RequestandResponsenow strictly follow the
close()method andcloseevent semantics.
Closing theRequestdoes not interrupt the underlying TCP/IP in
order to allow still sending back a valid response message.
Closing theResponsedoes terminate the underlying TCP/IP
connection in order to clean up resources.You should make sure to always attach a
requestevent listener
like above. TheServerwill not respond to an incoming HTTP
request otherwise and keep the TCP/IP connection pending until the
other side chooses to close the connection. -
Feature: Support
HTTP/1.1andHTTP/1.0forRequestandResponse.
(#124, #125, #126, #127, #128 by @clue and #139 by @legionth)The outgoing
Responsewill automatically use the same HTTP version as the
incomingRequestmessage and will only applyHTTP/1.1semantics if
applicable. This includes that theResponsewill automatically attach a
DateandConnection: closeheader if applicable.This implies that the
Servernow automatically responds with HTTP error
messages for invalid requests (status 400) and those exceeding internal
request header limits (status 431).