Merge branch 'master' of git.php.net:/pecl/http/pecl_http
[m6w6/ext-http] / tests / helper / pipeline.inc
diff --git a/tests/helper/pipeline.inc b/tests/helper/pipeline.inc
new file mode 100644 (file)
index 0000000..b7175c1
--- /dev/null
@@ -0,0 +1,26 @@
+<?php 
+
+include "server.inc";
+
+function respond($client, $msg) {
+       $r = new http\Env\Response;
+       $r->setEnvRequest($msg)
+               ->setHeader("X-Req", $msg->getRequestUrl())
+               ->send($client);
+}
+
+serve(function($client) {
+       $count = trim(fgets(STDIN));
+       
+       /* the peek message */
+       respond($client, new http\Message($client, false));
+       
+       /* pipelined messages */
+       $req = array();
+       for ($i=0; $i < $count; ++ $i) {
+               $req[] = new http\Message($client, false);
+       }
+       foreach ($req as $msg) {
+               respond($client, $msg);
+       }
+});