From efdbb46bf78df0d34936c536bd78b05abadd3a0d Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 30 Mar 2012 13:21:08 +0000 Subject: [PATCH] release dev10 --- package.xml | 9 +++---- php_http_curl_client.c | 6 ++--- phpunit/RequestTest.php | 47 +++++++++++++++++---------------- tests/factory.phpt | 26 +++++++++--------- tests/message001.phpt | 2 +- tests/persistenthandles001.phpt | 46 ++++++++++++++++---------------- tests/requestpool001.phpt | 33 +++++++++-------------- 7 files changed, 80 insertions(+), 89 deletions(-) diff --git a/package.xml b/package.xml index 5658d3a..e8c672e 100644 --- a/package.xml +++ b/package.xml @@ -18,8 +18,7 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be * 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; - Nevertheless, you have to use the http\Request\Factory to create your request/pool/datashare objects. +* The request ecosystem has been modularized to support different libraries, though for the moment only libcurl is supported. ]]> Michael Wallner @@ -27,9 +26,9 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be mike@php.net yes - 2012-03-23 + 2012-03-30 - 2.0.0dev9 + 2.0.0dev10 2.0.0 @@ -38,7 +37,7 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be BSD, revised diff --git a/php_http_curl_client.c b/php_http_curl_client.c index a285397..a2e0d3f 100644 --- a/php_http_curl_client.c +++ b/php_http_curl_client.c @@ -1026,6 +1026,7 @@ static STATUS php_http_curl_client_reset(php_http_client_t *h) STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_message_t *msg) { + size_t body_size; php_http_curl_client_t *curl = h->ctx; php_http_curl_client_storage_t *storage = get_storage(curl->handle); TSRMLS_FETCH_FROM_CTX(h->ts); @@ -1096,15 +1097,14 @@ STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_message_t *ms } /* attach request body */ - { + if ((body_size = php_http_message_body_size(&msg->body))) { /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.« * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method * does not allow a request body. */ - size_t body_size = php_http_message_body_size(&msg->body); - + php_stream_rewind(php_http_message_body_stream(&msg->body)); curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, &msg->body); curl_easy_setopt(curl->handle, CURLOPT_READDATA, &msg->body); curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size); diff --git a/phpunit/RequestTest.php b/phpunit/RequestTest.php index fccad01..56053ee 100644 --- a/phpunit/RequestTest.php +++ b/phpunit/RequestTest.php @@ -28,7 +28,7 @@ class RequestTest extends PHPUnit_Framework_TestCase protected $r; function setUp() { - $this->r = (new http\Request\Factory)->createRequest(); + $this->r = (new http\Client\Factory)->createClient(); $this->r->setOptions( array( "connecttimeout" => 30, @@ -38,10 +38,8 @@ class RequestTest extends PHPUnit_Framework_TestCase } function testClone() { - $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php"); $c = clone $this->r; - $c->setUrl("http://dev.iworks.at/ext-http/.print_headers.php"); - $this->assertNotEquals($this->r->send(), $c->send()); + $this->assertNotSame($this->r, $c); } function testObserver() { @@ -61,51 +59,52 @@ class RequestTest extends PHPUnit_Framework_TestCase } ) ); - $this->r->setUrl("http://dev.iworks.at/ext-http/")->send(); + $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/"))->send(null); $this->assertRegexp("/(\.-)+/", $this->r->pi); $this->assertCount(3, $this->r->getObservers()); } function testCookies() { - $this->r->setUrl("http://dev.iworks.at/ext-http/.cookie.php")->send(); + $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php"))->send(null); $this->assertNotContains("Cookie", (string) $this->r->getRequestMessage()); - $this->r->send(); + $this->r->send(null); $this->assertNotContains("Cookie", (string) $this->r->getRequestMessage()); - $this->r->enableCookies()->send(); + $this->r->enableCookies()->send(null); $this->assertNotContains("Cookie", (string) $this->r->getRequestMessage()); - $this->r->send(); + $this->r->send(null); $this->assertContains("Cookie", (string) $this->r->getRequestMessage()); - $this->assertCount(2, $this->r->getResponseCookies()); + $this->assertCount(2, $this->r->getResponseMessage()->getCookies()); } function testResetCookies() { - $this->r->setUrl("http://dev.iworks.at/ext-http/.cookie.php"); + $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php")); $this->r->enableCookies(); - $this->r->send(); + $this->r->send(null); $f = function ($a) { return $a->getCookies(); }; - $c = array_map($f, $this->r->getResponseCookies()); + $c = array_map($f, $this->r->getResponseMessage()->getCookies()); - $this->r->send(); - $this->assertEquals($c, array_map($f, $this->r->getResponseCookies())); + $this->r->send(null); + $this->assertEquals($c, array_map($f, $this->r->getResponseMessage()->getCookies())); $this->r->resetCookies(); - $this->r->send(); - $this->assertNotEquals($c, array_map($f, $this->r->getResponseCookies())); + $this->r->send(null); + $this->assertNotEquals($c, array_map($f, $this->r->getResponseMessage()->getCookies())); } function testHistory() { $body = new http\Message\Body; $body->append("foobar"); - $this->r->setBody($body); - $this->r->recordHistory = true; + $request = new http\Client\Request; + $request->setBody($body); + $request->setRequestMethod("POST"); + $request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php"); - $this->r->setMethod("POST"); - $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php"); + $this->r->recordHistory = true; + $this->r->send($request); - $this->r->send(); $this->assertStringMatchesFormat(<<r->getHistory()->toString(true)) ); - $this->r->send(); + + $this->r->send($request); + $this->assertStringMatchesFormat(<< --FILE-- "curl")); -$r = $f->createRequest(); +$r = $f->createClient(); $p = $f->createPool(); $s = $f->createDataShare(); @@ -33,9 +33,9 @@ var_dump( $f->getDriver() ); -foreach (array("Request", "Pool", "DataShare") as $type) { +foreach (array("Client", "Pool", "DataShare") as $type) { try { - var_dump((new http\Request\Factory(array("driver" => "nonexistant")))->{"create$type"}()); + var_dump((new http\Client\Factory(array("driver" => "nonexistant")))->{"create$type"}()); } catch (Exception $e) { echo $e->getMessage(), "\n"; } @@ -49,14 +49,14 @@ array(4) { [0]=> string(9) "MyFactory" [1]=> - string(9) "MyRequest" + string(8) "MyClient" [2]=> string(6) "MyPool" [3]=> string(7) "MyShare" } string(4) "curl" -requests are not supported by this driver +clients are not supported by this driver pools are not supported by this driver datashares are not supported by this driver Done diff --git a/tests/message001.phpt b/tests/message001.phpt index aa01e6d..e0eeddd 100644 --- a/tests/message001.phpt +++ b/tests/message001.phpt @@ -90,7 +90,7 @@ echo $m->getParentMessage(); echo "Done\n"; --EXPECTF-- Test -string(3) "0.0" +string(3) "1.1" bool(true) array(0) { } diff --git a/tests/persistenthandles001.phpt b/tests/persistenthandles001.phpt index dd7b8c7..01f5069 100644 --- a/tests/persistenthandles001.phpt +++ b/tests/persistenthandles001.phpt @@ -4,32 +4,26 @@ persistent handles --FILE-- "foo"))) - ->createRequest("http://dev.iworks.at") +(new http\Client\Factory(array("persistentHandleId" => "foo"))) + ->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at")) ->setOptions(array("connecttimeout"=> 90, "timeout" =>300)) - ->send(); -$r = (new http\Request\Factory(array("persistentHandleId" => "bar"))) - ->createRequest("http://dev.iworks.at") + ->send(null); +$r = (new http\Client\Factory(array("persistentHandleId" => "bar"))) + ->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at")) ->setOptions(array("connecttimeout"=> 90, "timeout" =>300)); var_dump(http\Env::statPersistentHandles()); http\Env::cleanPersistentHandles(); var_dump(http\Env::statPersistentHandles()); -$r->send(); +$r->send(null); var_dump(http\Env::statPersistentHandles()); ?> DONE --EXPECTF-- object(stdClass)#%d (3) { - ["http_request_datashare.curl"]=> - array(0) { - } - ["http_request_pool.curl"]=> - array(0) { - } - ["http_request.curl"]=> + ["http_client.curl"]=> array(2) { ["foo"]=> array(2) { @@ -46,15 +40,15 @@ object(stdClass)#%d (3) { int(0) } } -} -object(stdClass)#%d (3) { - ["http_request_datashare.curl"]=> + ["http_client_pool.curl"]=> array(0) { } - ["http_request_pool.curl"]=> + ["http_client_datashare.curl"]=> array(0) { } - ["http_request.curl"]=> +} +object(stdClass)#%d (3) { + ["http_client.curl"]=> array(1) { ["bar"]=> array(2) { @@ -64,15 +58,15 @@ object(stdClass)#%d (3) { int(0) } } -} -object(stdClass)#%d (3) { - ["http_request_datashare.curl"]=> + ["http_client_pool.curl"]=> array(0) { } - ["http_request_pool.curl"]=> + ["http_client_datashare.curl"]=> array(0) { } - ["http_request.curl"]=> +} +object(stdClass)#%d (3) { + ["http_client.curl"]=> array(1) { ["bar"]=> array(2) { @@ -82,5 +76,11 @@ object(stdClass)#%d (3) { int(0) } } + ["http_client_pool.curl"]=> + array(0) { + } + ["http_client_datashare.curl"]=> + array(0) { + } } DONE diff --git a/tests/requestpool001.phpt b/tests/requestpool001.phpt index 790823c..ff91a40 100644 --- a/tests/requestpool001.phpt +++ b/tests/requestpool001.phpt @@ -7,18 +7,13 @@ include 'skipif.inc'; --FILE-- $file) { $this->attach( - $this->factory->createRequest( - $url, - "GET", + $this->factory->createClient( array( 'redirect' => 5, 'compress' => GZIP, @@ -60,13 +53,13 @@ class Pool extends HttpRequestPool 'connecttimeout' => TOUT, 'lastmodified' => is_file($file)?filemtime($file):0 ) - ) + )->setRequest(new http\Client\Request("GET", $url)) ); } while ($this->once()) { if (!$this->wait()) { - throw new HttpSocketException; + throw new http\Exception; } } } @@ -75,19 +68,19 @@ class Pool extends HttpRequestPool { try { $rc = parent::once(); - } catch (HttpRequestException $x) { + } catch (http\Exception $x) { // a request may have thrown an exception, // but it is still save to continue echo $x->getMessage(), "\n"; } - foreach ($this->getFinishedRequests() as $r) { + foreach ($this->getFinished() as $r) { $this->detach($r); - $u = $r->getUrl(); - $c = $r->getResponseCode(); + $u = $r->getRequest()->getRequestUrl(); + $c = $r->getResponseMessage()->getResponseCode(); try { - $b = $r->getResponseBody(); + $b = $r->getResponseMessage()->getBody(); } catch (\Exception $e) { echo $e->getMessage(), "\n"; $b = ""; @@ -102,9 +95,7 @@ class Pool extends HttpRequestPool if ($a = each($this->rem)) { list($url, $file) = $a; $this->attach( - $this->factory->createRequest( - $url, - "GET", + $this->factory->createClient( array( 'redirect' => 5, 'compress' => GZIP, @@ -112,7 +103,7 @@ class Pool extends HttpRequestPool 'connecttimeout' => TOUT, 'lastmodified' => is_file($file)?filemtime($file):0 ) - ) + )->setRequest(new http\Client\Request("GET", $url)) ); } } @@ -126,7 +117,7 @@ define('RMAX', 10); chdir(__DIR__); $time = microtime(true); -$factory = new HttpRequestFactory(array("driver" => "curl", "requestPoolClass" => "Pool")); +$factory = new http\Client\Factory(array("driver" => "curl", "clientPoolClass" => "Pool")); $factory->createPool()->run($factory); printf("Elapsed: %0.3fs\n", microtime(true)-$time); -- 2.30.2