client test and fixes
authorMichael Wallner <mike@php.net>
Fri, 5 Apr 2013 13:04:48 +0000 (13:04 +0000)
committerMichael Wallner <mike@php.net>
Fri, 5 Apr 2013 13:04:48 +0000 (13:04 +0000)
26 files changed:
package.xml
php_http_client.c
php_http_client.h
php_http_client_curl.c
php_http_misc.c
php_http_misc.h
tests/client001.phpt [new file with mode: 0644]
tests/client002.phpt [new file with mode: 0644]
tests/client003.phpt [new file with mode: 0644]
tests/client004.phpt [new file with mode: 0644]
tests/client005.phpt [new file with mode: 0644]
tests/client006.phpt [new file with mode: 0644]
tests/client007.phpt [new file with mode: 0644]
tests/client008.phpt [new file with mode: 0644]
tests/client009.phpt [new file with mode: 0644]
tests/client010.phpt [new file with mode: 0644]
tests/clientresponse001.phpt [new file with mode: 0644]
tests/clientresponse002.phpt [new file with mode: 0644]
tests/clientresponse003.phpt [new file with mode: 0644]
tests/envrequestfiles001.phpt
tests/envrequestfiles002.phpt
tests/envrequestform.phpt
tests/envrequestquery.phpt
tests/envresponsecodes.phpt
tests/message001.phpt
tests/querystring_001.phpt

index ca927789336478420f720c070900713545dad0d2..ac62a6aa2cadf6bd7eb50c1b279427cc8938c498 100644 (file)
  <channel>pecl.php.net</channel>
  <summary>Extended HTTP Support</summary>
  <description><![CDATA[
-Extended HTTP support. Again. Keep in mind that it's got the major version 2, because it's incompatible with pecl_http v1.
+This HTTP extension aims to provide a convenient and powerful 
+set of functionality for one of PHPs major applications.
 
-* Introduces the http namespace.
-* Message bodies have been remodeled to use PHP temporary streams instead of in-memory buffers.
-* The utterly misunderstood HttpResponse class has been reimplemented as http\Env\Response inheriting http\Message.
-* Currently, there's only one Exception class left, http\Exception.
-* Errors triggered by the extension can be configured statically by http\Object::$defaultErrorHandling or inherited http\Object->errorHandling.
-* The request ecosystem has been modularized to support different libraries, though for the moment only libcurl is supported.
+It eases handling of HTTP urls, headers and messages, provides 
+means for negotiation of a client's preferred content type, 
+language and charset, as well as a convenient way to send any 
+arbitrary data with caching and resuming capabilities.
+
+It provides powerful request functionality, if built with CURL 
+support. Parallel requests are available for PHP 5 and greater.
 ]]></description>
  <lead>
   <name>Michael Wallner</name>
@@ -36,7 +38,15 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be
   <api>beta</api>
  </stability>
  <license>BSD, revised</license>
- <notes><![CDATA[-
+ <notes><![CDATA[
+Extended HTTP support. Again. Keep in mind that it's got the major version 2, because it's incompatible with pecl_http v1.
+
+* Introduces the http namespace.
+* Message bodies have been remodeled to use PHP temporary streams instead of in-memory buffers.
+* The utterly misunderstood HttpResponse class has been reimplemented as http\Env\Response inheriting http\Message.
+* Currently, there's only one Exception class left, http\Exception.
+* Errors triggered by the extension can be configured statically by http\Object::$defaultErrorHandling or inherited http\Object->errorHandling.
+* The request ecosystem has been modularized to support different libraries, though for the moment only libcurl is supported.
 ]]></notes>
  <contents>
   <dir name="/">
index 0826bbff77087d39abc98c8344c1b67b8babfa36..f23322d12a457ca8a6bc116176f164e9773b8638 100644 (file)
@@ -8,27 +8,40 @@
  */
 static HashTable php_http_client_drivers;
 
-PHP_HTTP_API STATUS php_http_client_driver_add(const char *name_str, uint name_len, php_http_client_driver_t *driver)
+PHP_HTTP_API STATUS php_http_client_driver_add(php_http_client_driver_t *driver)
 {
-       return zend_hash_add(&php_http_client_drivers, name_str, name_len + 1, (void *) driver, sizeof(php_http_client_driver_t), NULL);
+       return zend_hash_add(&php_http_client_drivers, driver->name_str, driver->name_len + 1, (void *) driver, sizeof(php_http_client_driver_t), NULL);
 }
 
-PHP_HTTP_API STATUS php_http_client_driver_get(char **name_str, uint *name_len, php_http_client_driver_t *driver)
+PHP_HTTP_API STATUS php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver)
 {
        php_http_client_driver_t *tmp;
 
-       if (*name_str && SUCCESS == zend_hash_find(&php_http_client_drivers, *name_str, (*name_len) + 1, (void *) &tmp)) {
-               *driver = *tmp;
-               return SUCCESS;
-       } else if (SUCCESS == zend_hash_get_current_data(&php_http_client_drivers, (void *) &tmp)) {
-               zend_hash_get_current_key_ex(&php_http_client_drivers, name_str, name_len, NULL, 0, NULL);
-               --(*name_len);
+       if ((name_str && SUCCESS == zend_hash_find(&php_http_client_drivers, name_str, name_len + 1, (void *) &tmp))
+       ||      (SUCCESS == zend_hash_get_current_data(&php_http_client_drivers, (void *) &tmp))) {
                *driver = *tmp;
                return SUCCESS;
        }
        return FAILURE;
 }
 
+static int apply_driver_list(void *p, void *arg TSRMLS_DC)
+{
+       php_http_client_driver_t *d = p;
+       zval *zname;
+
+       MAKE_STD_ZVAL(zname);
+       ZVAL_STRINGL(zname, d->name_str, d->name_len, 1);
+
+       zend_hash_next_index_insert(arg, &zname, sizeof(zval *), NULL);
+       return ZEND_HASH_APPLY_KEEP;
+}
+
+PHP_HTTP_API void php_http_client_driver_list(HashTable *ht TSRMLS_DC)
+{
+       zend_hash_apply_with_argument(&php_http_client_drivers, apply_driver_list, ht TSRMLS_CC);
+}
+
 void php_http_client_options_set_subr(zval *this_ptr, char *key, size_t len, zval *opts, int overwrite TSRMLS_DC)
 {
        if (overwrite || (opts && zend_hash_num_elements(Z_ARRVAL_P(opts)))) {
@@ -420,20 +433,30 @@ static STATUS handle_response(void *arg, php_http_client_t *client, php_http_cli
        return SUCCESS;
 }
 
-static void handle_progress(void *arg, php_http_client_t *client, php_http_client_enqueue_t *e, php_http_client_progress_state_t *state)
+static void handle_progress(void *arg, php_http_client_t *client, php_http_client_enqueue_t *e, php_http_client_progress_state_t *progress)
 {
-       zval *zrequest, *retval = NULL, *zclient;
+       zval *zrequest, *zprogress, *retval = NULL, *zclient;
        TSRMLS_FETCH_FROM_CTX(client->ts);
 
        MAKE_STD_ZVAL(zclient);
        ZVAL_OBJVAL(zclient, ((php_http_client_object_t *) arg)->zv, 1);
        MAKE_STD_ZVAL(zrequest);
        ZVAL_OBJVAL(zrequest, ((php_http_message_object_t *) e->opaque)->zv, 1);
+       MAKE_STD_ZVAL(zprogress);
+       object_init(zprogress);
+       add_property_bool(zprogress, "started", progress->started);
+       add_property_bool(zprogress, "finished", progress->finished);
+       add_property_string(zprogress, "info", STR_PTR(progress->info), 1);
+       add_property_double(zprogress, "dltotal", progress->dl.total);
+       add_property_double(zprogress, "dlnow", progress->dl.now);
+       add_property_double(zprogress, "ultotal", progress->ul.total);
+       add_property_double(zprogress, "ulnow", progress->ul.now);
        with_error_handling(EH_NORMAL, NULL) {
-               zend_call_method_with_1_params(&zclient, NULL, NULL, "notify", &retval, zrequest);
+               zend_call_method_with_2_params(&zclient, NULL, NULL, "notify", &retval, zrequest, zprogress);
        } end_error_handling();
        zval_ptr_dtor(&zclient);
        zval_ptr_dtor(&zrequest);
+       zval_ptr_dtor(&zprogress);
        if (retval) {
                zval_ptr_dtor(&retval);
        }
@@ -460,7 +483,7 @@ static PHP_METHOD(HttpClient, __construct)
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &driver_str, &driver_len, &persistent_handle_str, &persistent_handle_len)) {
                        php_http_client_driver_t driver;
 
-                       if (SUCCESS == php_http_client_driver_get(&driver_str, (uint *) &driver_len, &driver)) {
+                       if (SUCCESS == php_http_client_driver_get(driver_str, driver_len, &driver)) {
                                php_resource_factory_t *rf = NULL;
                                php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                                zval *os;
@@ -475,7 +498,8 @@ static PHP_METHOD(HttpClient, __construct)
                                        size_t name_len;
                                        php_persistent_handle_factory_t *pf;
 
-                                       name_len = spprintf(&name_str, 0, "http\\Client\\%s", php_http_pretty_key(driver_str, driver_len, 1, 1));
+                                       name_len = spprintf(&name_str, 0, "http\\Client\\%s", driver.name_str);
+                                       php_http_pretty_key(name_str + sizeof("http\\Client"), driver.name_len, 1, 1);
 
                                        if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, persistent_handle_str, persistent_handle_len, NULL, NULL TSRMLS_CC))) {
                                                rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon);
@@ -535,7 +559,7 @@ static HashTable *combined_options(zval *client, zval *request TSRMLS_DC)
        }
        if (z_roptions) {
                if (Z_TYPE_P(z_roptions) == IS_ARRAY) {
-                       array_join(Z_ARRVAL_P(z_roptions), options, 1, 0);
+                       array_join(Z_ARRVAL_P(z_roptions), options, 0, 0);
                }
                zval_ptr_dtor(&z_roptions);
        }
@@ -792,18 +816,11 @@ static PHP_METHOD(HttpClient, enableEvents)
 
 static int notify(zend_object_iterator *iter, void *puser TSRMLS_DC)
 {
-       zval **observer = NULL, **args = puser;
+       zval **observer = NULL, ***args = puser;
 
        iter->funcs->get_current_data(iter, &observer TSRMLS_CC);
        if (observer) {
-               zval *retval = NULL;
-
-               zend_call_method(observer, NULL, NULL, ZEND_STRL("update"), &retval, args[1]?2:1, args[0], args[1] TSRMLS_CC);
-               if (retval) {
-                       zval_ptr_dtor(&retval);
-               }
-
-               return SUCCESS;
+               return php_http_method_call(*observer, ZEND_STRL("update"), args[2]?3:args[1]?2:args[0]?1:0, args, NULL TSRMLS_CC);
        }
        return FAILURE;
 }
@@ -813,23 +830,30 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_notify, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpClient, notify)
 {
-       zval *request = NULL;
+       zval *request = NULL, *zprogress = NULL;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!", &request, php_http_client_request_get_class_entry())) {
-               zval *args[2], *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!o!", &request, php_http_client_request_get_class_entry(), &zprogress)) {
+               zval **args[3], *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
 
                if (Z_TYPE_P(observers) == IS_OBJECT) {
                        Z_ADDREF_P(getThis());
+                       args[0] = &getThis();
                        if (request) {
                                Z_ADDREF_P(request);
                        }
-                       args[0] = getThis();
-                       args[1] = request;
-                       spl_iterator_apply(observers, notify, &args TSRMLS_CC);
+                       args[1] = &request;
+                       if (zprogress) {
+                               Z_ADDREF_P(zprogress);
+                       }
+                       args[2] = &zprogress;
+                       spl_iterator_apply(observers, notify, args TSRMLS_CC);
                        zval_ptr_dtor(&getThis());
                        if (request) {
                                zval_ptr_dtor(&request);
                        }
+                       if (zprogress) {
+                               zval_ptr_dtor(&zprogress);
+                       }
                }
        }
 
@@ -1025,6 +1049,15 @@ static PHP_METHOD(HttpClient, getCookies)
        }
 }
 
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getAvailableDrivers, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpClient, getAvailableDrivers) {
+       if (SUCCESS == zend_parse_parameters_none()) {
+               array_init(return_value);
+               php_http_client_driver_list(Z_ARRVAL_P(return_value) TSRMLS_CC);
+       }
+}
+
 static zend_function_entry php_http_client_methods[] = {
        PHP_ME(HttpClient, __construct, ai_HttpClient_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_ME(HttpClient, reset, ai_HttpClient_reset, ZEND_ACC_PUBLIC)
@@ -1052,6 +1085,7 @@ static zend_function_entry php_http_client_methods[] = {
        PHP_ME(HttpClient, setCookies, ai_HttpClient_setCookies, ZEND_ACC_PUBLIC)
        PHP_ME(HttpClient, addCookies, ai_HttpClient_addCookies, ZEND_ACC_PUBLIC)
        PHP_ME(HttpClient, getCookies, ai_HttpClient_getCookies, ZEND_ACC_PUBLIC)
+       PHP_ME(HttpClient, getAvailableDrivers, ai_HttpClient_getAvailableDrivers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        EMPTY_FUNCTION_ENTRY
 };
 
index 42b713146dc915d61918c20076b9977a0ec5e021..9a7c630bbe52dc644518188f2b99ba657bdb99e1 100644 (file)
@@ -50,11 +50,13 @@ typedef struct php_http_client_ops {
 } php_http_client_ops_t;
 
 typedef struct php_http_client_driver {
+       const char *name_str;
+       size_t name_len;
        php_http_client_ops_t *client_ops;
 } php_http_client_driver_t;
 
-PHP_HTTP_API STATUS php_http_client_driver_add(const char *name_str, uint name_len, php_http_client_driver_t *driver);
-PHP_HTTP_API STATUS php_http_client_driver_get(char **name_str, uint *name_len, php_http_client_driver_t *driver);
+PHP_HTTP_API STATUS php_http_client_driver_add(php_http_client_driver_t *driver);
+PHP_HTTP_API STATUS php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver);
 
 typedef struct php_http_client_progress_state {
        struct {
index fb8ecf678f3e5e07366f7e772fd18d6551704b2a..460f62bafa3f49e2af7eb7131281c67673ae7468 100644 (file)
@@ -1862,10 +1862,11 @@ PHP_MINIT_FUNCTION(http_client_curl)
 {
        php_http_options_t *options;
        php_http_client_driver_t driver = {
+               ZEND_STRL("curl"),
                &php_http_client_curl_ops
        };
 
-       if (SUCCESS != php_http_client_driver_add(ZEND_STRL("curl"), &driver)) {
+       if (SUCCESS != php_http_client_driver_add(&driver)) {
                        return FAILURE;
                }
 
index f14354abfab28291799129062f97f8a46553d108..092662a346583b9f62ae32447a193320136e8289 100644 (file)
@@ -289,6 +289,34 @@ void php_http_error(long type TSRMLS_DC, long code, const char *format, ...)
        va_end(args);
 }
 
+/* ZEND */
+
+STATUS php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval **argv[], zval **retval_ptr TSRMLS_DC)
+{
+       zend_fcall_info fci;
+       zval zmethod;
+       zval *retval;
+       STATUS rv;
+
+       fci.size = sizeof(fci);
+       fci.object_ptr = object;
+       fci.function_name = &zmethod;
+       fci.retval_ptr_ptr = retval_ptr ? retval_ptr : &retval;
+       fci.param_count = argc;
+       fci.params = argv;
+       fci.no_separation = 1;
+       fci.symbol_table = NULL;
+       fci.function_table = NULL;
+
+       INIT_PZVAL(&zmethod);
+       ZVAL_STRINGL(&zmethod, method_str, method_len, 0);
+       rv = zend_call_function(&fci, NULL TSRMLS_CC);
+
+       if (!retval_ptr && retval) {
+               zval_ptr_dtor(&retval);
+       }
+       return rv;
+}
 /*
  * Local variables:
  * tab-width: 4
index 69076e71fbc2201b114ec3ecf8309231e100e7de..314fc24b4a91f9f84a7fd1dd390c5176bc952086 100644 (file)
@@ -200,6 +200,8 @@ static inline STATUS php_http_ini_entry(const char *name_str, size_t name_len, c
        return FAILURE;
 }
 
+STATUS php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval **argv[], zval **retval_ptr TSRMLS_DC);
+
 /* return bool (v == SUCCESS) */
 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
diff --git a/tests/client001.phpt b/tests/client001.phpt
new file mode 100644 (file)
index 0000000..8071afa
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+client drivers
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       var_dump($client instanceof http\Client);
+}
+
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:bool\(true\)
+)+Done
diff --git a/tests/client002.phpt b/tests/client002.phpt
new file mode 100644 (file)
index 0000000..44ff3d1
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+client observer
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+class Observer implements SplObserver
+{
+       function update(SplSubject $client, http\Client\Request $request = null, StdClass $progress = null) {
+               echo "P";
+               if ($client->getProgressInfo($request) != $progress) {
+                       var_dump($progress);
+               }
+       }
+}
+
+$observer = new Observer;
+$request = new http\Client\Request("GET", "http://www.example.org/");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $client->attach($observer);
+       $client->enqueue($request);
+       $client->send();
+}
+
+?>
+
+Done
+--EXPECTREGEX--
+Test
+P+
+Done
diff --git a/tests/client003.phpt b/tests/client003.phpt
new file mode 100644 (file)
index 0000000..b09c299
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+client once & wait
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("GET", "http://www.example.org/");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $client->enqueue($request);
+       
+       while ($client->once()) {
+               $client->wait(.1);
+       }
+       
+       if (!$client->getResponse()) {
+               var_dump($client);
+       }
+}
+?>
+Done
+--EXPECT--
+Test
+Done
diff --git a/tests/client004.phpt b/tests/client004.phpt
new file mode 100644 (file)
index 0000000..22ad9fe
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+client reset
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("GET", "http://www.example.org");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $client->enqueue($request)->send();
+       if (!($client->getResponse($request) instanceof http\Client\Response)) {
+               var_dump($client);
+       }
+       try {
+               $client->enqueue($request);
+       } catch (Exception $e) {
+               echo $e->getMessage(),"\n";
+       }
+       $client->reset();
+       if (($response = $client->getResponse())) {
+               var_dump($response);
+       }
+       $client->enqueue($request);
+}
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:Failed to enqueue request; request already in queue
+)+Done
diff --git a/tests/client005.phpt b/tests/client005.phpt
new file mode 100644 (file)
index 0000000..36a3f0a
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+client response callback
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $client->enqueue(new http\Client\Request("GET", "http://www.example.org"), function($response) {
+               echo "R\n";
+               if (!($response instanceof http\Client\Response)) {
+                       var_dump($response);
+               }
+       });
+       $client->send();
+}
+
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:R
+)+Done
diff --git a/tests/client006.phpt b/tests/client006.phpt
new file mode 100644 (file)
index 0000000..762e044
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+client response callback + dequeue
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+function response($response) {
+       echo "R\n";
+       if (!($response instanceof http\Client\Response)) {
+               var_dump($response);
+       }
+       
+       /* automatically dequeue */
+       return true;
+}
+
+$request = new http\Client\Request("GET", "http://www.example.org");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       for ($i=0; $i < 2; ++ $i) {
+               $client->enqueue($request, "response");
+               $client->send();
+               try {
+                       $client->dequeue($request);
+               } catch (Exception $e) {
+                       echo $e->getMessage(),"\n";
+               }
+       }
+}
+
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:(?:R
+Failed to dequeue request; request not in queue
+)+)+Done
diff --git a/tests/client007.phpt b/tests/client007.phpt
new file mode 100644 (file)
index 0000000..8421b51
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+client response callback + requeue
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+function response($response) {
+       echo "R\n";
+       if (!($response instanceof http\Client\Response)) {
+               var_dump($response);
+       }
+}
+
+$request = new http\Client\Request("GET", "http://www.example.org");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       for ($i=0; $i < 2; ++ $i) {
+               $client->requeue($request, "response");
+               $client->send();
+       }
+}
+
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:R
+R
+)+Done
diff --git a/tests/client008.phpt b/tests/client008.phpt
new file mode 100644 (file)
index 0000000..d7fe358
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+client features
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("GET", "http://www.example.org");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $client->enablePipelining(true);
+       $client->enableEvents(true);
+       
+       $client->enqueue($request);
+       $client->enqueue(clone $request);
+       $client->enqueue(clone $request);
+       
+       $client->send();
+       
+       while ($client->getResponse()) {
+               echo "R\n";
+       }
+}
+
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:R
+R
+R
+)+Done
diff --git a/tests/client009.phpt b/tests/client009.phpt
new file mode 100644 (file)
index 0000000..937045d
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+client static cookies
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.print_request.php");
+
+function x($a) {
+       $r[key($a)]=end($a);
+       $r[key($a)]=reset($a);
+       return $r;
+}
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $client->setCookies(array("test" => "bar"));
+       $client->addCookies(array("foo" => "test"));
+       $client->enqueue($request);
+       $client->send();
+       var_dump($client->getResponse()->getBody()->toString());
+       $request->setOptions(array("cookies" => x($client->getCookies())));
+       $client->requeue($request);
+       $client->send();
+       var_dump($client->getResponse()->getBody()->toString());
+}
+
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:string\(46\) "Array
+\(
+    \[test\] \=\> bar
+    \[foo\] \=\> test
+\)
+"
+string\(46\) "Array
+\(
+    \[test\] \=\> test
+    \[foo\] \=\> bar
+\)
+"
+)+Done
diff --git a/tests/client010.phpt b/tests/client010.phpt
new file mode 100644 (file)
index 0000000..7563a77
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+client upload
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("POST", "http://dev.iworks.at/ext-http/.print_request.php");
+$request->getBody()->addForm(null, array("file"=>__FILE__, "name"=>"upload", "type"=>"text/plain"));
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $client->enqueue($request)->send();
+       var_dump($client->getResponse()->getBody()->toString());
+}
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:string\(\d+\) "Array
+\(
+    \[upload\] \=\> Array
+        \(
+            \[name\] \=\> client010\.php
+            \[type\] \=\> text\/plain
+            \[tmp_name\] \=\> .*
+            \[error\] \=\> 0
+            \[size\] \=\> \d+
+        \)
+
+\)
+"
+)+Done
diff --git a/tests/clientresponse001.phpt b/tests/clientresponse001.phpt
new file mode 100644 (file)
index 0000000..2f25291
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+client response cookie
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie1.php");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       foreach($client->enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) {
+               var_dump($cookies->toArray());
+       }
+}
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:array\(7\) \{
+  \["cookies"\]\=\>
+  array\(2\) \{
+    \["foo"\]\=\>
+    string\(3\) "bar"
+    \["bar"\]\=\>
+    string\(3\) "foo"
+  \}
+  \["extras"\]\=\>
+  array\(0\) \{
+  \}
+  \["flags"\]\=\>
+  int\(0\)
+  \["expires"\]\=\>
+  int\(\-1\)
+  \["max\-age"\]\=\>
+  int\(\-1\)
+  \["path"\]\=\>
+  string\(0\) ""
+  \["domain"\]\=\>
+  string\(0\) ""
+\}
+)+Done
diff --git a/tests/clientresponse002.phpt b/tests/clientresponse002.phpt
new file mode 100644 (file)
index 0000000..6cc3c3a
--- /dev/null
@@ -0,0 +1,63 @@
+--TEST--
+client response cookies
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       foreach($client->enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) {
+               var_dump($cookies->toArray());
+       }
+}
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:array\(7\) \{
+  \["cookies"\]\=\>
+  array\(1\) \{
+    \["temp"\]\=\>
+    string\(13\) "\d+\.\d+"
+  \}
+  \["extras"\]\=\>
+  array\(0\) \{
+  \}
+  \["flags"\]\=\>
+  int\(0\)
+  \["expires"\]\=\>
+  int\(\-1\)
+  \["max\-age"\]\=\>
+  int\(\-1\)
+  \["path"\]\=\>
+  string\(0\) ""
+  \["domain"\]\=\>
+  string\(0\) ""
+\}
+array\(7\) \{
+  \["cookies"\]\=\>
+  array\(1\) \{
+    \["perm"\]\=\>
+    string\(13\) "\d+\.\d+"
+  \}
+  \["extras"\]\=\>
+  array\(0\) \{
+  \}
+  \["flags"\]\=\>
+  int\(0\)
+  \["expires"\]\=\>
+  int\(\d+\)
+  \["max\-age"\]\=\>
+  int\(\-1\)
+  \["path"\]\=\>
+  string\(0\) ""
+  \["domain"\]\=\>
+  string\(0\) ""
+\}
+)+Done
diff --git a/tests/clientresponse003.phpt b/tests/clientresponse003.phpt
new file mode 100644 (file)
index 0000000..a119951
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+client response transfer info
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$request = new http\Client\Request("GET", "http://www.example.org");
+
+foreach (http\Client::getAvailableDrivers() as $driver) {
+       $client = new http\Client($driver);
+       $response = $client->enqueue($request)->send()->getResponse();
+       var_dump($response->getTransferInfo("response_code"));
+       var_dump(count($response->getTransferInfo()));
+}
+?>
+Done
+--EXPECTREGEX--
+Test
+(?:int\([1-5]\d\d\)
+int\(\d\d\)
+)+Done
index 5b1cd2e9d6d25c2804b1ff488a24c441ad20a7ea..9a577c9d8b366840f284378796dca404b16e29c5 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-http\Env\Request grabbing $_FILES
+env request grabbing $_FILES
 --SKIPIF--
 <?php include "skipif.inc"; ?>
 --POST_RAW--
index 85b44dbe68e0425b86fe655e52ce7ef2ed29a285..afc5144cf4c1b27b1039970f219d0321c5385d0d 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-http\Env\Request grabbing $_FILES from array
+env request grabbing $_FILES from array
 --SKIPIF--
 <?php include "skipif.inc"; ?>
 --POST_RAW--
index c2086bb8b5734f235b7245424d6a67f90e8e2403..337bb5495e8dbd9e697ad8cf0cccafa242224e51 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-http\Env\Request getForm
+env request form
 --SKIPIF--
 <?php include "skipif.inc"; ?>
 --POST--
index 87f168d9ad5b5b2b48e2ec1136184b2bc53901a8..2e21ab9a1e8262d5debefee593e9738437faa360 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-http\Env\Request getQuery
+env request query
 --SKIPIF--
 <?php include "skipif.inc"; ?>
 --GET--
index 21d7bbfb0f78b49686b64a7ec4394d2d6563d15d..ec6ea21a33eb67596775747215fb2ae3c5aa8fa4 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-http\Env response codes
+env response codes
 --SKIPIF--
 <?php include "skipif.inc"; ?>
 --FILE--
index 9060ee47bb56e78052ecc2f358f1aa739f413060..230fd6b8a6deeb858867f9dbd2a1fa36977c4914 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Message
+message
 --SKIPIF--
 <?php
 include "skipif.inc";
index 585bdd62d7d9370bff7be0a5f60962be679d7327..203be335e541d03edeb41e47842a5f73e03e2c42 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-http\QueryString
+query string
 --SKIPIF--
 <?php
 include("skipif.inc");