add pipelining test
[m6w6/ext-http] / tests / proxy.inc
index d6803db656c15280b98578e85f2621c9b91e43ee..61b20dd1c1b38e3a26190d5d401216387991bc07 100644 (file)
@@ -1,25 +1,21 @@
 <?php 
 
-foreach (range(8000, 9000) as $port) {
-       if (($server = stream_socket_server("tcp://localhost:$port"))) {
-               fprintf(STDERR, "%s\n", $port);
-               if (($client = stream_socket_accept($server))) {
-                       /* this might be a proxy connect or a standard request */
-                       $request = new http\Message($client, false);
-                       
-                       if ($request->getHeader("Proxy-Connection")) {
-                               $response = new http\Env\Response;
-                               $response->send($client);
-                               
-                               /* soak up the request following the connect */
-                               new http\Message($client, false);
-                       }
-                       
-                       /* return the initial message as response body */
-                       $response = new http\Env\Response;
-                       $response->getBody()->append($request);
-                       $response->send($client);
-               }
-               return;
+include "server.inc";
+
+serve(function($client) {
+       /* this might be a proxy connect or a standard request */
+       $request = new http\Message($client, false);
+       
+       if ($request->getHeader("Proxy-Connection")) {
+               $response = new http\Env\Response;
+               $response->send($client);
+               
+               /* soak up the request following the connect */
+               new http\Message($client, false);
        }
-}
\ No newline at end of file
+       
+       /* return the initial message as response body */
+       $response = new http\Env\Response;
+       $response->getBody()->append($request);
+       $response->send($client);
+});