Swoole\Http\Response->trailer

Declaration

<?php
Swoole\Http\Response->trailer(string $key, string $value)

Parameters

key

The key of HTTP response header

value

The value of HTTP response header

Return

Response

Description

Send a HTTP trailer response header to HTTP client. A trailer header is appended to the HTTP body. This can be used for both HTTP 1.1 and HTTP 2 responses.

Example

<?php
$http->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
     $response->header('trailer', 'Content-MD5');
     $data = 'hello world';
     $response->write($data);
     $response->trailer('Content-MD5', md5($data));
     $response->end();
 });
HTTP/1.1 200 OK 
Content-Type: text/plain 
Transfer-Encoding: chunked
Trailer: Expires

7\r\n 
Swoole.co.uk\r\n 
9\r\n 
Developer\r\n
0\r\n 
Expires: Wed, 21 Oct 2015 07:28:00 GMT\r\n
\r\n