815b46339b672574284138ec976cf8da0b472827
[m6w6/ext-http] / tests / pipeline.inc
1 <?php
2
3 include "server.inc";
4
5 function respond($client, $msg) {
6 (new http\Env\Response)->setEnvRequest($msg)
7 ->setHeader("X-Req", $msg->getRequestUrl())
8 ->send($client);
9 }
10
11 serve(function($client) {
12 $count = trim(fgets(STDIN));
13
14 /* the peek message */
15 respond($client, new http\Message($client, false));
16
17 /* pipelined messages */
18 $req = array();
19 for ($i=0; $i < $count; ++ $i) {
20 $req[] = new http\Message($client, false);
21 }
22 foreach ($req as $msg) {
23 respond($client, $msg);
24 }
25 });