<email>mike@php.net</email>
<active>yes</active>
</lead>
- <date>2012-12-31</date>
+ <date>2013-08-12</date>
<version>
- <release>2.0.0dev</release>
+ <release>2.0.0beta5</release>
<api>2.0.0</api>
</version>
<stability>
<file role="test" name="client008.phpt"/>
<file role="test" name="client009.phpt"/>
<file role="test" name="client010.phpt"/>
+ <file role="test" name="client011.phpt"/>
+ <file role="test" name="client012.phpt"/>
+ <file role="test" name="client013.phpt"/>
<file role="test" name="clientrequest001.phpt"/>
<file role="test" name="clientrequest002.phpt"/>
<file role="test" name="clientrequest003.phpt"/>
<file role="test" name="envrequestjson001.phpt"/>
<file role="test" name="envrequestjson002.phpt"/>
<file role="test" name="envrequestquery.phpt"/>
+ <file role="test" name="envresponse001.phpt"/>
+ <file role="test" name="envresponse002.phpt"/>
+ <file role="test" name="envresponse003.phpt"/>
+ <file role="test" name="envresponse004.phpt"/>
+ <file role="test" name="envresponse005.phpt"/>
+ <file role="test" name="envresponse006.phpt"/>
+ <file role="test" name="envresponse007.phpt"/>
+ <file role="test" name="envresponse008.phpt"/>
+ <file role="test" name="envresponse009.phpt"/>
+ <file role="test" name="envresponse010.phpt"/>
+ <file role="test" name="envresponse011.phpt"/>
+ <file role="test" name="envresponse012.phpt"/>
+ <file role="test" name="envresponse013.phpt"/>
+ <file role="test" name="envresponse014.phpt"/>
<file role="test" name="envresponsebody001.phpt"/>
<file role="test" name="envresponsebody002.phpt"/>
<file role="test" name="envresponsecodes.phpt"/>
<file role="test" name="etag001.phpt"/>
<file role="test" name="filterchunked.phpt"/>
<file role="test" name="filterzlib.phpt"/>
+ <file role="test" name="header001.phpt"/>
+ <file role="test" name="header002.phpt"/>
+ <file role="test" name="header003.phpt"/>
+ <file role="test" name="header004.phpt"/>
+ <file role="test" name="header005.phpt"/>
+ <file role="test" name="header006.phpt"/>
+ <file role="test" name="header007.phpt"/>
+ <file role="test" name="header008.phpt"/>
+ <file role="test" name="header009.phpt"/>
<file role="test" name="info_001.phpt"/>
<file role="test" name="info.phpt"/>
<file role="test" name="message001.phpt"/>
<file role="test" name="message004.phpt"/>
<file role="test" name="message005.phpt"/>
<file role="test" name="message006.phpt"/>
+ <file role="test" name="message007.phpt"/>
+ <file role="test" name="message008.phpt"/>
+ <file role="test" name="message009.phpt"/>
+ <file role="test" name="message010.phpt"/>
+ <file role="test" name="message011.phpt"/>
+ <file role="test" name="message012.phpt"/>
+ <file role="test" name="message013.phpt"/>
+ <file role="test" name="message014.phpt"/>
+ <file role="test" name="message015.phpt"/>
<file role="test" name="negotiate001.phpt"/>
+ <file role="test" name="object001.phpt"/>
+ <file role="test" name="object002.phpt"/>
+ <file role="test" name="object003.phpt"/>
+ <file role="test" name="object004.phpt"/>
+ <file role="test" name="object005.phpt"/>
+ <file role="test" name="object006.phpt"/>
+ <file role="test" name="object007.phpt"/>
+ <file role="test" name="object008.phpt"/>
+ <file role="test" name="object009.phpt"/>
<file role="test" name="params001.phpt"/>
<file role="test" name="params002.phpt"/>
<file role="test" name="phpunit.phpt"/>
<file role="test" name="propertyproxy001.phpt"/>
<file role="test" name="querystring_001.phpt"/>
- <file role="test" name="response001.phpt"/>
- <file role="test" name="response002.phpt"/>
- <file role="test" name="response003.phpt"/>
- <file role="test" name="response004.phpt"/>
- <file role="test" name="response005.phpt"/>
- <file role="test" name="response006.phpt"/>
- <file role="test" name="response007.phpt"/>
- <file role="test" name="response008.phpt"/>
- <file role="test" name="response009.phpt"/>
- <file role="test" name="response010.phpt"/>
- <file role="test" name="response011.phpt"/>
- <file role="test" name="response012.phpt"/>
- <file role="test" name="response013.phpt"/>
- <file role="test" name="response014.phpt"/>
<file role="test" name="serialize001.phpt"/>
<file role="test" name="url001.phpt"/>
<file role="test" name="version001.phpt"/>
</dir>
<dir name="phpunit">
- <file role="test" name="ClientTest.php"/>
<file role="test" name="CookieTest.php"/>
<file role="test" name="EncodingTest.php"/>
- <file role="test" name="HeaderTest.php"/>
- <file role="test" name="MessageTest.php"/>
<file role="test" name="MessageBodyTest.php"/>
- <file role="test" name="ObjectTest.php"/>
<file role="test" name="ParamsTest.php"/>
<file role="test" name="QueryStringTest.php"/>
<file role="test" name="UrlTest.php"/>
#ifndef PHP_EXT_HTTP_H
#define PHP_EXT_HTTP_H
-#define PHP_HTTP_EXT_VERSION "2.0.0dev"
+#define PHP_HTTP_EXT_VERSION "2.0.0beta5"
zend_module_entry http_module_entry;
#define phpext_http_ptr &http_module_entry
+++ /dev/null
-<?php
-
-class ProgressObserver1 implements SplObserver {
- function update(SplSubject $c, $r = null) {
- if ($c->getProgressInfo($r)) $c->pi .= "-";
- }
-}
-class ProgressObserver2 implements SplObserver {
- function update(SplSubject $c, $r = null) {
- if ($c->getProgressInfo($r)) $c->pi .= ".";
- }
-}
-class CallbackObserver implements SplObserver {
- public $callback;
- function __construct($callback) {
- $this->callback = $callback;
- }
- function update(SplSubject $c, $r = null) {
- call_user_func($this->callback, $c, $r);
- }
-}
-
-class RequestTest extends PHPUnit_Framework_TestCase
-{
- /**
- * @var http\Client
- */
- protected $r;
-
- function setUp() {
- $this->r = new http\Client;
- $this->r->pi = "";
- $this->r->setOptions(
- array(
- "connecttimeout" => 30,
- "timeout" => 300,
- )
- );
- $this->r->setOptions(
- array(
- "timeout" => 600
- )
- );
- $this->assertEquals(
- array(
- "connecttimeout" => 30,
- "timeout" => 600,
- ),
- $this->r->getOptions()
- );
- }
-
- function testObserver() {
- $test = $this;
- $this->r->attach($o1 = new ProgressObserver1);
- $this->r->attach($o2 = new ProgressObserver2);
- $this->r->attach(
- $o3 = new CallbackObserver(
- function ($c, $r) use ($test) {
- $p = (array) $c->getProgressInfo($r);
- $test->assertArrayHasKey("started", $p);
- $test->assertArrayHasKey("finished", $p);
- $test->assertArrayHasKey("dlnow", $p);
- $test->assertArrayHasKey("ulnow", $p);
- $test->assertArrayHasKey("dltotal", $p);
- $test->assertArrayHasKey("ultotal", $p);
- $test->assertArrayHasKey("info", $p);
- }
- )
- );
- $this->r->enqueue(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/"))->send();
- $this->assertRegexp("/(\.-)+/", $this->r->pi);
- $this->assertCount(3, $this->r->getObservers());
- $this->r->detach($o1);
- $this->assertCount(2, $this->r->getObservers());
- $this->r->detach($o2);
- $this->assertCount(1, $this->r->getObservers());
- $this->r->detach($o3);
- $this->assertCount(0, $this->r->getObservers());
- }
-
- function testSsl() {
- $this->r->setSslOptions(array("verify_peer" => true));
- $this->r->addSslOptions(array("verify_host" => 2));
- $this->assertEquals(
- array(
- "verify_peer" => true,
- "verify_host" => 2,
- ),
- $this->r->getSslOptions()
- );
- $this->r->enqueue($req = new http\Client\Request("GET", "https://twitter.com/"));
- $this->r->send();
- $ti = $this->r->getTransferInfo($req);
- $this->assertArrayHasKey("ssl_engines", $ti);
- $this->assertGreaterThan(0, count($ti["ssl_engines"]));
- }
-
- function testHistory() {
- $body = new http\Message\Body;
- $body->append("foobar");
-
- $request = new http\Client\Request;
- $request->setBody($body);
- $request->setRequestMethod("POST");
- $request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php");
-
- $this->r->recordHistory = true;
- $this->r->enqueue($request)->send();
-
- $this->assertStringMatchesFormat(<<<HTTP
-POST /ext-http/.print_request.php HTTP/1.1
-User-Agent: %s
-Host: dev.iworks.at
-Accept: */*
-Content-Length: 6
-Content-Type: application/x-www-form-urlencoded
-X-Original-Content-Length: 6
-
-foobar
-HTTP/1.1 200 OK
-Date: %s
-Server: %s
-Vary: %s
-Content-Length: 19
-Content-Type: text/html
-X-Original-Content-Length: 19
-
-string(6) "foobar"
-
-HTTP
- , str_replace("\r", "", $this->r->getHistory()->toString(true))
- );
-
-
- $this->r->requeue($request)->send();
-
- $this->assertStringMatchesFormat(<<<HTTP
-POST /ext-http/.print_request.php HTTP/1.1
-User-Agent: %s
-Host: dev.iworks.at
-Accept: */*
-Content-Length: 6
-Content-Type: application/x-www-form-urlencoded
-X-Original-Content-Length: 6
-
-foobar
-HTTP/1.1 200 OK
-Date: %s
-Server: %s
-Vary: %s
-Content-Length: 19
-Content-Type: text/html
-X-Original-Content-Length: 19
-
-string(6) "foobar"
-
-POST /ext-http/.print_request.php HTTP/1.1
-User-Agent: %s
-Host: dev.iworks.at
-Accept: */*
-Content-Length: 6
-Content-Type: application/x-www-form-urlencoded
-X-Original-Content-Length: 6
-
-foobar
-HTTP/1.1 200 OK
-Date: %s
-Server: %s
-Vary: %s
-Content-Length: 19
-Content-Type: text/html
-X-Original-Content-Length: 19
-
-string(6) "foobar"
-
-HTTP
- , str_replace("\r", "", $this->r->getHistory()->toString(true))
- );
- }
-}
-
+++ /dev/null
-<?php
-
-class HeaderTest extends PHPUnit_Framework_TestCase {
- function setUp() {
-
- }
- function testString() {
- $h = new http\Header("foo", "bar");
- $this->assertEquals("Foo: bar", (string) $h);
- }
-
- function testSerialize() {
- $h = new http\Header("foo", "bar");
- $this->assertEquals("Foo: bar", (string) unserialize(serialize($h)));
- }
-
- function testNumeric() {
- $h = new http\Header(123, 456);
- $this->assertEquals("123: 456", (string) $h);
- $this->assertEquals("123: 456", (string) unserialize(serialize($h)));
- }
-
- function testMatch() {
- $ae = new http\Header("Accept-encoding", "gzip, deflate");
- $this->assertTrue($ae->match("gzip", http\Header::MATCH_WORD));
- $this->assertTrue($ae->match("gzip", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
- $this->assertFalse($ae->match("gzip", http\Header::MATCH_STRICT));
- $this->assertTrue($ae->match("deflate", http\Header::MATCH_WORD));
- $this->assertTrue($ae->match("deflate", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
- $this->assertFalse($ae->match("deflate", http\Header::MATCH_STRICT));
-
- $this->assertFalse($ae->match("zip", http\Header::MATCH_WORD));
- $this->assertFalse($ae->match("gzip", http\Header::MATCH_FULL));
- }
-
- function testNegotiate() {
- $a = new http\Header("Accept", "text/html, text/plain;q=0.5, */*;q=0");
- $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html")));
- $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html"), $rs));
- $this->assertEquals(array("text/html"=>0.99, "text/plain"=>0.5), $rs);
- $this->assertEquals("text/plain", $a->negotiate(array("foo/bar", "text/plain"), $rs));
- $this->assertEquals(array("text/plain"=>0.5), $rs);
- $this->assertEquals("foo/bar", $a->negotiate(array("foo/bar"), $rs));
- $this->assertEquals(array(), $rs);
- }
-
- function testParse() {
- $header = "Foo: bar\nBar: foo\n";
- $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo"), http\Header::parse($header));
- $headers = http\Header::parse($header, "http\\Header");
- $this->assertCount(2, $headers);
- $this->assertContainsOnlyInstancesOf("http\\Header", $headers);
- }
-
- function testParseError() {
- $header = "wass\nup";
- $this->setExpectedException("PHPUnit_Framework_Error_Warning", "Could not parse headers");
- $this->assertFalse(http\Header::parse($header));
- }
-
- function testParams() {
- $header = new http\Header("Cache-control", "public, must-revalidate, max-age=0");
- $this->assertEquals(
- array(
- "public" => array("value" => true, "arguments" => array()),
- "must-revalidate" => array("value" => true, "arguments" => array()),
- "max-age" => array("value" => 0, "arguments" => array()),
- ),
- $header->getParams()->params
- );
- }
-
- function testParamsWithArgs() {
- $header = new http\Header("Custom", '"foo" is "bar". "bar" is "bis" where "bis" is "where".');
- $this->assertEquals(
- array(
- "foo" => array("value" => "bar", "arguments" => array()),
- "bar" => array("value" => "bis", "arguments" => array("bis" => "where"))
- ),
- $header->getParams(".", "where", "is")->params
- );
- }
-}
+++ /dev/null
-<?php
-
-class strval {
- private $str;
- function __construct($str) {
- $this->str = $str;
- }
- function __toString() {
- return (string) $this->str;
- }
-}
-
-class message extends http\Message {
- function __call($m, $args) {
- if (preg_match("/^test(get|set)(.*)\$/i", $m, $match)) {
- list(, $getset, $prop) = $match;
- $prop = strtolower($prop[0]).substr($prop,1);
- switch(strtolower($getset)) {
- case "get":
- return $this->$prop;
- case "set":
- $this->$prop = current($args);
- break;
- }
- }
- }
-}
-
-class MessageTest extends PHPUnit_Framework_TestCase
-{
- function testProperties() {
- $test = new message;
- $this->assertEquals(0, $test->testGetType());
- $this->assertEquals(null, $test->testGetBody());
- $this->assertEquals("", $test->testGetRequestMethod());
- $this->assertEquals("", $test->testGetRequestUrl());
- $this->assertEquals("", $test->testGetResponseStatus());
- $this->assertEquals(0, $test->testGetResponseCode());
- $this->assertEquals("1.1", $test->testGetHttpVersion());
- $this->assertEquals(array(), $test->testGetHeaders());
- $this->assertEquals(null, $test->testGetParentMessage());
- $test->testSetType(http\Message::TYPE_REQUEST);
- $this->assertEquals(http\Message::TYPE_REQUEST, $test->testGetType());
- $this->assertEquals(http\Message::TYPE_REQUEST, $test->getType());
- $body = new http\Message\Body;
- $test->testSetBody($body);
- $this->assertEquals($body, $test->testGetBody());
- $this->assertEquals($body, $test->getBody());
- $file = fopen(__FILE__,"r");
- $test->testSetBody($file);
- $this->assertEquals($file, $test->testGetBody()->getResource());
- $this->assertEquals($file, $test->getBody()->getResource());
- $test->testSetBody("data");
- $this->assertEquals("data", (string) $test->testGetBody());
- $this->assertEquals("data", (string) $test->getBody());
- $test->testSetRequestMethod("HEAD");
- $this->assertEquals("HEAD", $test->testGetRequestMethod());
- $this->assertEquals("HEAD", $test->getRequestMethod());
- $test->testSetRequestUrl("/");
- $this->assertEquals("/", $test->testGetRequestUrl());
- $this->assertEquals("/", $test->getRequestUrl());
- $this->assertEquals("HEAD / HTTP/1.1", $test->getInfo());
- $test->testSetType(http\Message::TYPE_RESPONSE);
- $test->setResponseStatus("Created");
- $this->assertEquals("Created", $test->testGetResponseStatus());
- $this->assertEquals("Created", $test->getResponseStatus());
- $test->setResponseCode(201);
- $this->assertEquals(201, $test->testGetResponseCode());
- $this->assertEquals(201, $test->getResponseCode());
- $test->testSetResponseStatus("Ok");
- $this->assertEquals("Ok", $test->testGetResponseStatus());
- $this->assertEquals("Ok", $test->getResponseStatus());
- $test->testSetResponseCode(200);
- $this->assertEquals(200, $test->testGetResponseCode());
- $this->assertEquals(200, $test->getResponseCode());
- $test->testSetHttpVersion("1.0");
- $this->assertEquals("1.0", $test->testGetHttpVersion());
- $this->assertEquals("1.0", $test->getHttpVersion());
- $this->assertEquals("HTTP/1.0 200 OK", $test->getInfo());
- $test->setHttpVersion("1.1");
- $this->assertEquals("1.1", $test->testGetHttpVersion());
- $this->assertEquals("1.1", $test->getHttpVersion());
- $this->assertEquals("HTTP/1.1 200 OK", $test->getInfo());
- $test->setInfo("HTTP/1.1 201 Created");
- $this->assertEquals("Created", $test->testGetResponseStatus());
- $this->assertEquals("Created", $test->getResponseStatus());
- $this->assertEquals(201, $test->testGetResponseCode());
- $this->assertEquals(201, $test->getResponseCode());
- $this->assertEquals("1.1", $test->testGetHttpVersion());
- $this->assertEquals("1.1", $test->getHttpVersion());
- $test->testSetHeaders(array("Foo" => "bar"));
- $this->assertEquals(array("Foo" => "bar"), $test->testGetHeaders());
- $this->assertEquals(array("Foo" => "bar"), $test->getHeaders());
- $this->assertEquals("bar", $test->getHeader("foo"));
- $this->assertEquals(null, $test->getHeader("bar"));
- $parent = new message;
- $test->testSetParentMessage($parent);
- $this->assertEquals($parent, $test->testGetParentMessage());
- $this->assertEquals($parent, $test->getParentMessage());
- }
-
- function testAddBody() {
- $m = new http\Message;
- $body = new http\Message\Body;
- $body->append("foo");
- $m->addBody($body);
- $body = new http\Message\Body;
- $body->append("bar");
- $m->addBody($body);
- $this->assertEquals("foobar", (string) $m->getBody());
- }
-
- function testAddHeaders() {
- $m = new http\Message;
- $m->addHeaders(array("foo"=>"bar","bar"=>"foo"));
- $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo"), $m->getHeaders());
- $m->addHeaders(array("key"=>"val","more"=>"Stuff"));
- $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo","Key"=>"val","More"=>"Stuff"), $m->getHeaders());
- }
-
- function testArrayHeaders() {
- $m = new http\Message("GET / HTTP/1.1");
- $m->addHeader("Accept", "text/html");
- $m->addHeader("Accept", "text/xml;q=0");
- $m->addHeader("Accept", "text/plain;q=0.5");
- $this->assertEquals(
- "GET / HTTP/1.1\r\n".
- "Accept: text/html, text/xml;q=0, text/plain;q=0.5\r\n",
- $m->toString()
- );
- }
-
- function testHeaderValueTypes() {
- $m = new http\Message("HTTP/1.1 200 Ok");
- $m->addHeader("Bool", true);
- $m->addHeader("Int", 123);
- $m->addHeader("Float", 1.23);
- $m->addHeader("Array", array(1,2,3));
- $m->addHeader("Object", new strval("test"));
- $m->addHeader("Set-Cookie",
- array(
- array(
- "cookies" => array("foo" => "bar"),
- "expires" => date_create("2012-12-31 22:59:59 GMT")->format(
- DateTime::COOKIE
- ),
- "path" => "/somewhere"
- )
- )
- );
- $m->addHeader("Set-Cookie", "val=0");
-
- $this->assertEquals(
- "HTTP/1.1 200 Ok\r\n".
- "Bool: true\r\n".
- "Int: 123\r\n".
- "Float: 1.23\r\n".
- "Array: 1, 2, 3\r\n".
- "Object: test\r\n".
- "Set-Cookie: foo=bar; path=/somewhere; expires=Mon, 31 Dec 2012 22:59:59 GMT; \r\n".
- "Set-Cookie: val=0\r\n",
- $m->toString()
- );
- }
-
- function testDetach() {
- $m = new http\Message(
- "HTTP/1.1 200 Ok\r\n".
- "HTTP/1.1 201 Created\n".
- "HTTP/1.1 302 Found\r\n"
- );
-
- $this->assertCount(3, $m);
- $d = $m->detach();
- $this->assertCount(3, $m);
- $this->assertCount(1, $d);
-
- $this->assertEquals("HTTP/1.1 302 Found\r\n\r\n", $d->toString(true));
- }
-
- function testPrepend() {
- for ($i=0; $i<9; ++$i) {
- $a[] = new http\Message("HTTP/1.1 ".($i+200));
- }
-
- foreach ($a as $m) {
- if (isset($p)) $m->prepend($p);
- $p = $m;
- }
-
- $this->assertEquals(
- "HTTP/1.1 200\r\n\r\n".
- "HTTP/1.1 201\r\n\r\n".
- "HTTP/1.1 202\r\n\r\n".
- "HTTP/1.1 203\r\n\r\n".
- "HTTP/1.1 204\r\n\r\n".
- "HTTP/1.1 205\r\n\r\n".
- "HTTP/1.1 206\r\n\r\n".
- "HTTP/1.1 207\r\n\r\n".
- "HTTP/1.1 208\r\n\r\n",
- $m->toString(true)
- );
- }
-
- function testEmptyUrlWarning() {
- $m = new http\Message;
- $this->setExpectedException("PHPUnit_Framework_Error_Notice");
- $m->setRequestUrl("/foo");
- $m->setType(http\Message::TYPE_REQUEST);
- $this->setExpectedException("PHPUnit_Framework_Error_Warning");
- $m->setRequestUrl("");
- }
-
- function testEmptyParentMessage() {
- $m = new http\Message;
- try {
- $m->getParentMessage();
- $this->assertFalse("this code should not be reached");
- } catch (http\Exception $e) {
- $this->assertEquals("HttpMessage does not have a parent message", $e->getMessage());
- }
- }
-
- function testPrependError() {
- $m = new http\Message("HTTP/1.1 200\r\nHTTP/1.1 201");
- try {
- $m->prepend($m->getParentMessage());
- $this->assertFalse("this code should not be reached");
- } catch (http\Exception $e) {
- $this->assertEquals("Cannot prepend a message located within the same message chain", $e->getMessage());
- }
- }
-
- function testToCallback() {
- $m = new http\Message("HTTP/1.1 200 Ok");
- $m->addHeader("Content-Type", "text/plain");
- $m->getBody()->append("this\nis\nthe\ntext");
-
- $d = new http\Encoding\Stream\Deflate;
- $s = "";
- $m->toCallback(function ($m, $data) use ($d, &$s) {
- $s.=$d->update($data);
- });
- $s.=$d->finish();
- $this->assertEquals($m->toString(), http\Encoding\Stream\Inflate::decode($s));
- }
-
- function testToStream() {
- $m = new http\Message("HTTP/1.1 200 Ok");
- $m->addHeader("Content-Type", "text/plain");
- $m->getBody()->append("this\nis\nthe\ntext");
-
- $f = tmpfile();
- $m->toStream($f);
- rewind($f);
- $this->assertEquals((string) $m, stream_get_contents($f));
- fclose($f);
- }
-
- function testBoundary() {
- $p = new http\Message;
- $p->addHeader("Content-Type", "text/plain");
- $p->getBody()->append("data");
-
- $m = new http\Message("HTTP/1.1 200");
- $m->getBody()->addPart($p);
- $this->assertStringMatchesFormat(
- "HTTP/1.1 200\r\n".
- "Content-Length: %d\r\n".
- "Content-Type: multipart/form-data; boundary=\"%x.%x\"\r\n".
- "\r\n".
- "--%x.%x\r\n".
- "Content-Type: text/plain\r\n".
- "Content-Length: 4\r\n".
- "\r\n".
- "data\r\n".
- "--%x.%x--\r\n".
- "",
- str_replace("\r", "", $m->toString()) // phpunit replaces \r\n with \n
- );
- }
-}
-
+++ /dev/null
-<?php
-
-class eh extends http\Object {
-}
-
-class ObjectTest extends PHPUnit_Framework_TestCase {
- function testDefaultErrorHandling() {
- $this->assertEquals(http\Object::EH_NORMAL, http\Object::getDefaultErrorHandling());
- http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
- $this->assertEquals(http\Object::EH_SUPPRESS, http\Object::getDefaultErrorHandling());
- }
-
- function testErrorHandling() {
- $eh = new eh;
- $this->assertEquals(eh::EH_NORMAL, $eh->getErrorHandling());
- $eh->setErrorHandling(eh::EH_SUPPRESS);
- $this->assertEquals(eh::EH_SUPPRESS, $eh->getErrorHandling());
- }
-
- function testSuppress() {
- http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
- $o = new eh;
- $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
- }
-
- function testException() {
- http\Object::setDefaultErrorHandling(http\Object::EH_THROW);
- $this->setExpectedException("http\\Exception");
- $o = new eh;
- $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
- }
-
- function testNormalError() {
- http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);
- $this->setExpectedException("PHPUnit_Framework_Error_Warning");
- $o = new eh;
- $o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
- }
-
- function testSuppress2() {
- $eh = new eh;
- $eh->setErrorHandling(http\Object::EH_SUPPRESS);
- $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
- }
-
- function testException2() {
- $eh = new eh;
- $eh->setErrorHandling(http\Object::EH_THROW);
- $this->setExpectedException("http\\Exception");
- $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
- }
-
- function testNormalError2() {
- $eh = new eh;
- $eh->setErrorHandling(http\Object::EH_NORMAL);
- $this->setExpectedException("PHPUnit_Framework_Error_Warning");
- $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
- }
-
- function testUnknownDefaultErrorHandling() {
- $this->setExpectedException("PHPUnit_Framework_Error_Warning");
- http\Object::setDefaultErrorHandling(12345);
- }
-
- function testUnknownErrorHandling() {
- $eh = new eh;
- $this->setExpectedException("PHPUnit_Framework_Error_Warning");
- $eh->setErrorHandling(12345);
- }
-}
-
--- /dev/null
+--TEST--
+client history
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$body = new http\Message\Body;
+$body->append("foobar");
+
+$request = new http\Client\Request;
+$request->setBody($body);
+$request->setRequestMethod("POST");
+$request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php");
+
+$client = new http\Client;
+$client->recordHistory = true;
+
+$client->enqueue($request)->send();
+echo $client->getHistory()->toString(true);
+
+$client->requeue($request)->send();
+echo $client->getHistory()->toString(true);
+
+?>
+Done
+--EXPECTF--
+Test
+POST /ext-http/.print_request.php HTTP/1.1
+User-Agent: %s
+Host: dev.iworks.at
+Accept: */*
+Content-Length: 6
+Content-Type: application/x-www-form-urlencoded
+X-Original-Content-Length: 6
+
+foobar
+HTTP/1.1 200 OK
+Date: %s
+Server: %s
+Vary: %s
+Content-Length: 19
+Content-Type: text/html
+X-Original-Content-Length: 19
+
+string(6) "foobar"
+
+POST /ext-http/.print_request.php HTTP/1.1
+User-Agent: %s
+Host: dev.iworks.at
+Accept: */*
+Content-Length: 6
+Content-Type: application/x-www-form-urlencoded
+X-Original-Content-Length: 6
+
+foobar
+HTTP/1.1 200 OK
+Date: %s
+Server: %s
+Vary: %s
+Content-Length: 19
+Content-Type: text/html
+X-Original-Content-Length: 19
+
+string(6) "foobar"
+
+POST /ext-http/.print_request.php HTTP/1.1
+User-Agent: %s
+Host: dev.iworks.at
+Accept: */*
+Content-Length: 6
+Content-Type: application/x-www-form-urlencoded
+X-Original-Content-Length: 6
+
+foobar
+HTTP/1.1 200 OK
+Date: %s
+Server: %s
+Vary: %s
+Content-Length: 19
+Content-Type: text/html
+X-Original-Content-Length: 19
+
+string(6) "foobar"
+
+Done
--- /dev/null
+--TEST--
+client ssl
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$client = new http\Client;
+
+$client->setSslOptions(array("verify_peer" => true));
+$client->addSslOptions(array("verify_host" => 2));
+var_dump(
+ array(
+ "verify_peer" => true,
+ "verify_host" => 2,
+ ) === $client->getSslOptions()
+);
+
+$client->enqueue($req = new http\Client\Request("GET", "https://twitter.com/"));
+$client->send();
+
+$ti = $client->getTransferInfo($req);
+var_dump(array_key_exists("ssl_engines", $ti));
+var_dump(0 < count($ti["ssl_engines"]));
+?>
+Done
+--EXPECTF--
+Test
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+client observers
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class Client extends http\Client {
+ public $pi;
+}
+class ProgressObserver1 implements SplObserver {
+ function update(SplSubject $c, $r = null) {
+ if ($c->getProgressInfo($r)) $c->pi .= "-";
+ }
+}
+class ProgressObserver2 implements SplObserver {
+ function update(SplSubject $c, $r = null) {
+ if ($c->getProgressInfo($r)) $c->pi .= ".";
+ }
+}
+class CallbackObserver implements SplObserver {
+ public $callback;
+ function __construct($callback) {
+ $this->callback = $callback;
+ }
+ function update(SplSubject $c, $r = null) {
+ call_user_func($this->callback, $c, $r);
+ }
+}
+
+$client = new Client;
+$client->attach($o1 = new ProgressObserver1);
+$client->attach($o2 = new ProgressObserver2);
+$client->attach(
+ $o3 = new CallbackObserver(
+ function ($c, $r) {
+ $p = (array) $c->getProgressInfo($r);
+ var_dump(array_key_exists("started", $p));
+ var_dump(array_key_exists("finished", $p));
+ var_dump(array_key_exists("dlnow", $p));
+ var_dump(array_key_exists("ulnow", $p));
+ var_dump(array_key_exists("dltotal", $p));
+ var_dump(array_key_exists("ultotal", $p));
+ var_dump(array_key_exists("info", $p));
+ }
+ )
+);
+
+$client->enqueue(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/"))->send();
+var_dump(1 === preg_match("/(\.-)+/", $client->pi));
+var_dump(3 === count($client->getObservers()));
+$client->detach($o1);
+var_dump(2 === count($client->getObservers()));
+$client->detach($o2);
+var_dump(1 === count($client->getObservers()));
+$client->detach($o3);
+var_dump(0 === count($client->getObservers()));
+
+?>
+Done
+--EXPECTREGEX--
+Test\n(bool\(true\)\n)+Done
$r = new http\Client\Request("GET", "http://localhost");
var_dump($r === $r->setOptions($o = array("redirect"=>5, "timeout"=>5)));
var_dump($o === $r->getOptions());
+var_dump($r === $r->setOptions(array("timeout"=>50)));
+$o["timeout"] = 50;
+var_dump($o === $r->getOptions());
var_dump($r === $r->setSslOptions($o = array("verify_peer"=>false)));
var_dump($o === $r->getSslOptions());
bool(true)
bool(true)
bool(true)
+bool(true)
+bool(true)
Done
--TEST--
-request header
+env request header
--SKIPIF--
<? include "skipif.inc";
--POST--
--- /dev/null
+--TEST--
+env response message
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--POST--
+a=b
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+
+$r = new http\env\Response;
+$r->setHeader("foo","bar");
+$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
+$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
+$r->send();
+
+--EXPECTHEADERS--
+Foo: bar
+Content-Encoding: gzip
+Vary: Accept-Encoding
+--EXPECTREGEX--
+^\x1f\x8b\x08.+
--- /dev/null
+--TEST--
+env response cache negative
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+a=b
+--ENV--
+HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
+HTTP_IF_NONE_MATCH=0000-00-0000
+--FILE--
+<?php
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send();
+?>
+--EXPECTHEADERS--
+ETag: "abc"
+Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
+--EXPECT--
+<?php
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send();
+?>
--- /dev/null
+--TEST--
+env response ranges
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--ENV--
+HTTP_RANGE=bytes=2-4
+--GET--
+a=b
+--FILE--
+<?php
+
+$r = new http\Env\Response;
+$r->setContentType("text/plain");
+$r->setContentDisposition(
+ array("attachment" => array(array("filename" => basename(__FILE__))))
+);
+$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
+$r->send();
+
+?>
+--EXPECTHEADERS--
+Content-Type: text/plain
+--EXPECTF--
+php
--- /dev/null
+--TEST--
+env reponse callback
+--SKIPIF--
+<?php
+include "skipif.inc";
+if (version_compare(PHP_VERSION, "5.4.0", "<")) die("SKIP 5.3 ob is broken");
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+
+$r = new http\Env\Response;
+$r->setCacheControl("public,must-revalidate,max-age=0");
+$r->setThrottleRate(1, 0.1);
+ob_start($r);
+
+echo "foo";
+echo "bar";
+
+ob_end_flush();
+$r->send();
+--EXPECTHEADERS--
+Accept-Ranges: bytes
+Cache-Control: public,must-revalidate,max-age=0
+ETag: "9ef61f95"
+--EXPECTF--
+foobar
--- /dev/null
+--TEST--
+env response cache positive
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+a=b
+--ENV--
+HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:32 GMT
+--FILE--
+<?php
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
+$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
+$r->send();
+?>
+--EXPECTHEADERS--
+HTTP/1.1 304 Not Modified
+ETag: "abc"
+Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
+--EXPECT--
--- /dev/null
+--TEST--
+env response stream
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$f = tmpfile();
+
+$r = new http\Env\Response;
+$r->addHeader("foo", array("bar","baz"));
+$r->getBody()->append("foo");
+
+$r->send($f);
+
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+Done
+--EXPECT--
+Test
+string(77) "HTTP/1.1 200 OK
+Accept-Ranges: bytes
+Foo: bar, baz
+ETag: "8c736521"
+
+foo"
+Done
--- /dev/null
+--TEST--
+env response env request
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+echo "Test\n";
+
+$tmp = tmpfile();
+
+// modify HTTP env
+$req = new http\Env\Request;
+$req->setHeader("Range", "bytes=2-4");
+
+$res = new http\Env\Response;
+$res->setEnvRequest($req);
+$res->setContentType("text/plain");
+$res->getBody()->append("012345679");
+$res->send($tmp);
+
+rewind($tmp);
+var_dump(stream_get_contents($tmp));
+
+?>
+Done
+--EXPECTF--
+Test
+string(%d) "HTTP/1.1 206 Partial Content%c
+Accept-Ranges: bytes%c
+X-Powered-By: %s%c
+Content-Type: text/plain%c
+Content-Range: bytes 2-4/9%c
+%c
+234"
+Done
--- /dev/null
+--TEST--
+env response stream message
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+
+$f = tmpfile();
+
+$r = new http\env\Response;
+$r->setHeader("foo","bar");
+$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
+$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
+$r->send($f);
+
+rewind($f);
+var_dump(stream_get_contents($f));
+
+--EXPECTREGEX--
+string\(\d+\) "HTTP\/1\.1 200 OK
+Accept-Ranges: bytes
+Foo: bar
+Content-Encoding: gzip
+Vary: Accept-Encoding
+ETag: "\w+-\w+-\w+"
+Last-Modified: \w+, \d+ \w+ \d{4} \d\d:\d\d:\d\d GMT
+
+\x1f\x8b\x08.+
--- /dev/null
+--TEST--
+env response stream cache negative
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+a=b
+--ENV--
+HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
+HTTP_IF_NONE_MATCH=0000-00-0000
+--FILE--
+<?php
+$f = tmpfile();
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+--EXPECTF--
+string(%d) "HTTP/1.1 200 OK%c
+Accept-Ranges: bytes%c
+X-Powered-By: %s%c
+ETag: "abc"%c
+Last-Modified: %s%c
+%c
+<?php
+$f = tmpfile();
+$r = new http\Env\Response;
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+"
+
--- /dev/null
+--TEST--
+env response stream ranges
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--ENV--
+HTTP_RANGE=bytes=2-4
+--GET--
+a=b
+--FILE--
+<?php
+$f = tmpfile();
+$r = new http\Env\Response;
+$r->setContentType("text/plain");
+$r->setContentDisposition(
+ array("attachment" => array(array("filename" => basename(__FILE__))))
+);
+$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
+$r->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+?>
+--EXPECTF--
+string(%i) "HTTP/1.1 206 Partial Content%c
+Accept-Ranges: bytes%c
+X-Powered-By: PHP/%s%c
+Content-Type: text/plain%c
+Content-Range: bytes 2-4/311%c
+%c
+php"
--- /dev/null
+--TEST--
+env response cache positive with env message
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+dummy=1
+--FILE--
+<?php
+$e = new http\Env\Request;
+$e->setHeader("If-Modified-Since", "Fri, 13 Feb 2009 23:31:32 GMT");
+$r = new http\Env\Response;
+$r->setEnvRequest($e);
+$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
+$r->setEtag("abc");
+$r->setLastModified(1234567891);
+$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
+$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
+$r->send();
+?>
+--EXPECTHEADERS--
+HTTP/1.1 304 Not Modified
+ETag: "abc"
+Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
+--EXPECT--
--- /dev/null
+--TEST--
+env response content disposition
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+
+$r = new http\Env\Response;
+$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
+$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
+$r->send();
+
+?>
+--EXPECTHEADERS--
+Content-Disposition: attachment;filename=envresponse012.php
+--EXPECT--
+<?php
+
+$r = new http\Env\Response;
+$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
+$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
+$r->send();
+
+?>
+
--- /dev/null
+--TEST--
+env response deflate
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+
+$req = new http\Env\Request;
+$req->setHeader("Accept-Encoding", "deflate");
+
+$res = new http\Env\Response;
+$res->setCacheControl("public, max-age=3600");
+$res->setContentEncoding(http\Env\Response::CONTENT_ENCODING_GZIP);
+$res->getBody()->append("foobar");
+
+$res->setEnvRequest($req);
+$res->send();
+?>
+--EXPECTHEADERS--
+Content-Encoding: deflate
+Vary: Accept-Encoding
+Cache-Control: public, max-age=3600
+--EXPECTREGEX--
+^\x78\x9c.+
+
--- /dev/null
+--TEST--
+env response invalid ranges
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+$f = tmpfile();
+$req = new http\Env\Request;
+$req->setHeader("Range", "bytes=321-123,123-0");
+$res = new http\Env\Response;
+$res->getBody()->append("foobar");
+$res->setEnvRequest($req);
+$res->send($f);
+rewind($f);
+var_dump(stream_get_contents($f));
+--EXPECTF--
+string(96) "HTTP/1.1 416 Requested Range Not Satisfiable
+Accept-Ranges: bytes
+Content-Range: bytes */6
+
+"
+
--- /dev/null
+--TEST--
+header string
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$h = new http\Header("foo", "bar");
+var_dump("Foo: bar" === (string) $h);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
--- /dev/null
+--TEST--
+header numeric
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$h = new http\Header(123, 456);
+var_dump("123: 456" === (string) $h);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
--- /dev/null
+--TEST--
+header serialize
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$h = new http\Header("foo", "bar");
+var_dump("Foo: bar" === (string) unserialize(serialize($h)));
+$h = new http\Header(123, 456);
+var_dump("123: 456" === (string) unserialize(serialize($h)));
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+header match
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$ae = new http\Header("Accept-encoding", "gzip, deflate");
+var_dump($ae->match("gzip", http\Header::MATCH_WORD));
+var_dump($ae->match("gzip", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
+var_dump($ae->match("gzip", http\Header::MATCH_STRICT));
+var_dump($ae->match("deflate", http\Header::MATCH_WORD));
+var_dump($ae->match("deflate", http\Header::MATCH_WORD|http\Header::MATCH_CASE));
+var_dump($ae->match("deflate", http\Header::MATCH_STRICT));
+var_dump($ae->match("zip", http\Header::MATCH_WORD));
+var_dump($ae->match("gzip", http\Header::MATCH_FULL));
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+bool(false)
+bool(false)
+bool(false)
+Done
--- /dev/null
+--TEST--
+header negotiation
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$a = new http\Header("Accept", "text/html, text/plain;q=0.5, */*;q=0");
+var_dump("text/html" === $a->negotiate(array("text/plain","text/html")));
+var_dump("text/html" === $a->negotiate(array("text/plain","text/html"), $rs));
+var_dump(array("text/html"=>0.99, "text/plain"=>0.5) === $rs);
+var_dump("text/plain" === $a->negotiate(array("foo/bar", "text/plain"), $rs));
+var_dump(array("text/plain"=>0.5) === $rs);
+var_dump("foo/bar" === $a->negotiate(array("foo/bar"), $rs));
+var_dump(array() === $rs);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+header parsing
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = "Foo: bar\nBar: foo\n";
+var_dump(array("Foo"=>"bar","Bar"=>"foo") === http\Header::parse($header));
+
+$headers = http\Header::parse($header, "http\\Header");
+var_dump(2 === count($headers));
+var_dump(2 === array_reduce($headers, function($count, $header) {
+ return $count + ($header instanceof http\Header);
+}, 0));
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+header parse error
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = "wass\nup";
+/* this generates two warnings because of the LF ;) */
+http\Header::parse($header);
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Header::parse(): Could not parse headers in %s on line %d
+
+Warning: http\Header::parse(): Could not parse headers in %s on line %d
+Done
--- /dev/null
+--TEST--
+header params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = new http\Header("Cache-control", "public, must-revalidate, max-age=0");
+var_dump(
+ array(
+ "public" => array("value" => true, "arguments" => array()),
+ "must-revalidate" => array("value" => true, "arguments" => array()),
+ "max-age" => array("value" => "0", "arguments" => array()),
+ ) === $header->getParams()->params
+);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
--- /dev/null
+--TEST--
+header params w/ args
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$header = new http\Header("Custom", '"foo" is "bar". "bar" is "bis" where "bis" is "where".');
+var_dump(
+ array(
+ "foo" => array("value" => "bar", "arguments" => array()),
+ "bar" => array("value" => "bis", "arguments" => array("bis" => "where"))
+ ) === $header->getParams(".", "where", "is")->params
+);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
--TEST--
-env request Message
+env request message
--SKIPIF--
<?php include "skipif.inc"; ?>
--POST_RAW--
--- /dev/null
+--TEST--
+message to stream
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message("HTTP/1.1 200 Ok");
+$m->addHeader("Content-Type", "text/plain");
+$m->getBody()->append("this\nis\nthe\ntext");
+
+$f = tmpfile();
+$m->toStream($f);
+rewind($f);
+var_dump((string) $m === stream_get_contents($f));
+fclose($f);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
--- /dev/null
+--TEST--
+message to callback
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message("HTTP/1.1 200 Ok");
+$m->addHeader("Content-Type", "text/plain");
+$m->getBody()->append("this\nis\nthe\ntext");
+
+$d = new http\Encoding\Stream\Deflate;
+$s = "";
+$m->toCallback(function ($m, $data) use ($d, &$s) {
+ $s.=$d->update($data);
+});
+$s.=$d->finish();
+var_dump($m->toString() === http\Encoding\Stream\Inflate::decode($s));
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
--- /dev/null
+--TEST--
+message properties
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class message extends http\Message {
+ function __call($m, $args) {
+ if (preg_match("/^test(get|set)(.*)\$/i", $m, $match)) {
+ list(, $getset, $prop) = $match;
+ $prop = strtolower($prop[0]).substr($prop,1);
+ switch(strtolower($getset)) {
+ case "get":
+ return $this->$prop;
+ case "set":
+ $this->$prop = current($args);
+ break;
+ }
+ }
+ }
+}
+
+$test = new message;
+var_dump(0 === $test->testGetType());
+var_dump(null === $test->testGetBody());
+var_dump(null === $test->testGetRequestMethod());
+var_dump(null === $test->testGetRequestUrl());
+var_dump(null === $test->testGetResponseStatus());
+var_dump(null === $test->testGetResponseCode());
+var_dump("1.1" === $test->testGetHttpVersion());
+var_dump(array() === $test->testGetHeaders());
+var_dump(null === $test->testGetParentMessage());
+$test->testSetType(http\Message::TYPE_REQUEST);
+var_dump(http\Message::TYPE_REQUEST === $test->testGetType());
+var_dump(http\Message::TYPE_REQUEST === $test->getType());
+$body = new http\Message\Body;
+$test->testSetBody($body);
+var_dump($body === $test->testGetBody());
+var_dump($body === $test->getBody());
+$file = fopen(__FILE__,"r");
+$test->testSetBody($file);
+var_dump($file === $test->testGetBody()->getResource());
+var_dump($file === $test->getBody()->getResource());
+$test->testSetBody("data");
+var_dump("data" === (string) $test->testGetBody());
+var_dump("data" === (string) $test->getBody());
+$test->testSetRequestMethod("HEAD");
+var_dump("HEAD" === $test->testGetRequestMethod());
+var_dump("HEAD" === $test->getRequestMethod());
+$test->testSetRequestUrl("/");
+var_dump("/" === $test->testGetRequestUrl());
+var_dump("/" === $test->getRequestUrl());
+var_dump("HEAD / HTTP/1.1" === $test->getInfo());
+$test->testSetType(http\Message::TYPE_RESPONSE);
+$test->setResponseStatus("Created");
+var_dump("Created" === $test->testGetResponseStatus());
+var_dump("Created" === $test->getResponseStatus());
+$test->setResponseCode(201);
+var_dump(201 === $test->testGetResponseCode());
+var_dump(201 === $test->getResponseCode());
+$test->testSetResponseStatus("Ok");
+var_dump("Ok" === $test->testGetResponseStatus());
+var_dump("Ok" === $test->getResponseStatus());
+$test->testSetResponseCode(200);
+var_dump(200 === $test->testGetResponseCode());
+var_dump(200 === $test->getResponseCode());
+$test->testSetHttpVersion("1.0");
+var_dump("1.0" === $test->testGetHttpVersion());
+var_dump("1.0" === $test->getHttpVersion());
+var_dump("HTTP/1.0 200 OK" === $test->getInfo());
+$test->setHttpVersion("1.1");
+var_dump("1.1" === $test->testGetHttpVersion());
+var_dump("1.1" === $test->getHttpVersion());
+var_dump("HTTP/1.1 200 OK" === $test->getInfo());
+$test->setInfo("HTTP/1.1 201 Created");
+var_dump("Created" === $test->testGetResponseStatus());
+var_dump("Created" === $test->getResponseStatus());
+var_dump(201 === $test->testGetResponseCode());
+var_dump(201 === $test->getResponseCode());
+var_dump("1.1" === $test->testGetHttpVersion());
+var_dump("1.1" === $test->getHttpVersion());
+$test->testSetHeaders(array("Foo" => "bar"));
+var_dump(array("Foo" => "bar") === $test->testGetHeaders());
+var_dump(array("Foo" => "bar") === $test->getHeaders());
+var_dump("bar" === $test->getHeader("foo"));
+var_dump(false === $test->getHeader("bar"));
+$parent = new message;
+$test->testSetParentMessage($parent);
+var_dump($parent === $test->testGetParentMessage());
+var_dump($parent === $test->getParentMessage());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+message body
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message;
+$body = new http\Message\Body;
+$body->append("foo");
+$m->addBody($body);
+$body = new http\Message\Body;
+$body->append("bar");
+$m->addBody($body);
+var_dump("foobar" === (string) $m->getBody());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+Done
--- /dev/null
+--TEST--
+message headers
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+
+echo "Test\n";
+
+class strval {
+ private $str;
+ function __construct($str) {
+ $this->str = $str;
+ }
+ function __toString() {
+ return (string) $this->str;
+ }
+}
+
+$m = new http\Message;
+$m->addHeaders(array("foo"=>"bar","bar"=>"foo"));
+var_dump(array("Foo"=>"bar", "Bar"=>"foo") === $m->getHeaders());
+$m->addHeaders(array("key"=>"val","more"=>"Stuff"));
+var_dump(array("Foo"=>"bar", "Bar"=>"foo","Key"=>"val","More"=>"Stuff") === $m->getHeaders());
+$m = new http\Message("GET / HTTP/1.1");
+$m->addHeader("Accept", "text/html");
+$m->addHeader("Accept", "text/xml;q=0");
+$m->addHeader("Accept", "text/plain;q=0.5");
+var_dump(
+ "GET / HTTP/1.1\r\n".
+ "Accept: text/html, text/xml;q=0, text/plain;q=0.5\r\n" ===
+ $m->toString()
+);
+$m = new http\Message("HTTP/1.1 200 Ok");
+$m->addHeader("Bool", true);
+$m->addHeader("Int", 123);
+$m->addHeader("Float", 1.23);
+$m->addHeader("Array", array(1,2,3));
+$m->addHeader("Object", new strval("test"));
+$m->addHeader("Set-Cookie",
+ array(
+ array(
+ "cookies" => array("foo" => "bar"),
+ "expires" => date_create("2012-12-31 22:59:59 GMT")->format(
+ DateTime::COOKIE
+ ),
+ "path" => "/somewhere"
+ )
+ )
+);
+$m->addHeader("Set-Cookie", "val=0");
+
+var_dump(
+ "HTTP/1.1 200 Ok\r\n".
+ "Bool: true\r\n".
+ "Int: 123\r\n".
+ "Float: 1.23\r\n".
+ "Array: 1, 2, 3\r\n".
+ "Object: test\r\n".
+ "Set-Cookie: foo=bar; path=/somewhere; expires=Mon, 31 Dec 2012 22:59:59 GMT; \r\n".
+ "Set-Cookie: val=0\r\n" ===
+ $m->toString()
+);
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+message part
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$p = new http\Message;
+$p->addHeader("Content-Type", "text/plain");
+$p->getBody()->append("data");
+
+$m = new http\Message("HTTP/1.1 200");
+$m->getBody()->addPart($p);
+echo $m;
+
+?>
+Done
+--EXPECTF--
+Test
+HTTP/1.1 200
+Content-Length: %d
+Content-Type: multipart/form-data; boundary="%x.%x"
+
+--%x.%x
+Content-Type: text/plain
+Content-Length: 4
+
+data
+--%x.%x--
+Done
--- /dev/null
+--TEST--
+message detach
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message(
+ "HTTP/1.1 200 Ok\r\n".
+ "HTTP/1.1 201 Created\n".
+ "HTTP/1.1 302 Found\r\n"
+);
+
+var_dump(3 === count($m));
+$d = $m->detach();
+var_dump(3 === count($m));
+var_dump(1 === count($d));
+
+var_dump("HTTP/1.1 302 Found\r\n\r\n" === $d->toString(true));
+
+?>
+Done
+--EXPECTF--
+Test
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+message prepend
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+for ($i=0; $i<9; ++$i) {
+ $a[] = new http\Message("HTTP/1.1 ".($i+200));
+}
+
+foreach ($a as $m) {
+ if (isset($p)) $m->prepend($p);
+ $p = $m;
+}
+
+var_dump(
+ "HTTP/1.1 200\r\n\r\n".
+ "HTTP/1.1 201\r\n\r\n".
+ "HTTP/1.1 202\r\n\r\n".
+ "HTTP/1.1 203\r\n\r\n".
+ "HTTP/1.1 204\r\n\r\n".
+ "HTTP/1.1 205\r\n\r\n".
+ "HTTP/1.1 206\r\n\r\n".
+ "HTTP/1.1 207\r\n\r\n".
+ "HTTP/1.1 208\r\n\r\n" ===
+ $m->toString(true)
+);
+
+?>
+Done
+--EXPECTF--
+Test
+bool(true)
+Done
--- /dev/null
+--TEST--
+message errors
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$m = new http\Message;
+$m->setRequestUrl("/foo");
+$m->setType(http\Message::TYPE_REQUEST);
+$m->setRequestUrl("");
+
+$m = new http\Message;
+try {
+ $m->getParentMessage();
+ die("unreached");
+} catch (http\Exception $e) {
+ var_dump($e->getMessage());
+}
+
+$m = new http\Message("HTTP/1.1 200\r\nHTTP/1.1 201");
+try {
+ $m->prepend($m->getParentMessage());
+ die("unreached");
+} catch (http\Exception $e) {
+ var_dump($e->getMessage());
+}
+
+?>
+Done
+--EXPECTF--
+Test
+
+Notice: http\Message::setRequestUrl(): HttpMessage is not of type REQUEST in %s on line %d
+
+Warning: http\Message::setRequestUrl(): Cannot set HttpMessage::requestUrl to an empty string in %s on line %d
+string(42) "HttpMessage does not have a parent message"
+string(62) "Cannot prepend a message located within the same message chain"
+Done
--- /dev/null
+--TEST--
+object default error handling
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+var_dump(null === http\Object::getDefaultErrorHandling());
+http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
+var_dump(http\Object::EH_SUPPRESS === http\Object::getDefaultErrorHandling());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+object instance error handling
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+var_dump(null === $eh->getErrorHandling());
+$eh->setErrorHandling(eh::EH_SUPPRESS);
+var_dump(eh::EH_SUPPRESS === $eh->getErrorHandling());
+
+?>
+Done
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+object error suppression
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
+$o = new eh;
+$o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
+
+?>
+Done
+--EXPECT--
+Test
+Done
--- /dev/null
+--TEST--
+object error exception
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+http\Object::setDefaultErrorHandling(http\Object::EH_THROW);
+$o = new eh;
+$o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Fatal error: Uncaught exception 'http\Exception' with message 'exception' in %s:%d
+Stack trace:
+#0 %s(%d): http\Object->triggerError(512, 0, 'exception')
+#1 {main}
+ thrown in %s on line %d
--- /dev/null
+--TEST--
+object normal error
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);
+$o = new eh;
+$o->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Object::triggerError(): warning in %s on line %d
+Done
--- /dev/null
+--TEST--
+object error suppression2
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(http\Object::EH_SUPPRESS);
+$eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
+
+?>
+Done
+--EXPECTF--
+Test
+Done
--- /dev/null
+--TEST--
+object error exception2
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(http\Object::EH_THROW);
+$eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Fatal error: Uncaught exception 'http\Exception' with message 'exception' in %s:%d
+Stack trace:
+#0 /home/mike/src/pecl_http-DEV_2.svn/tests/object007.php(9): http\Object->triggerError(512, 0, 'exception')
+#1 {main}
+ thrown in %s on line %d
--- /dev/null
+--TEST--
+object normal error2
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(http\Object::EH_NORMAL);
+$eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Object::triggerError(): warning in %s on line %d
+Done
--- /dev/null
+--TEST--
+object unknown error handling
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+http\Object::setDefaultErrorHandling(12345);
+
+class eh extends http\Object {}
+
+$eh = new eh;
+$eh->setErrorHandling(12345);
+
+?>
+Done
+--EXPECTF--
+Test
+
+Warning: http\Object::setDefaultErrorHandling(): unknown error handling code (12345) in %s on line %d
+
+Warning: http\Object::setErrorHandling(): unknown error handling code (12345) in %s on line %d
+Done
+++ /dev/null
---TEST--
-env response Message
---SKIPIF--
-<?php include "skipif.inc"; ?>
---POST--
-a=b
---ENV--
-HTTP_ACCEPT_ENCODING=gzip
---FILE--
-<?php
-
-$r = new http\env\Response;
-$r->setHeader("foo","bar");
-$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
-$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
-$r->send();
-
---EXPECTHEADERS--
-Foo: bar
-Content-Encoding: gzip
-Vary: Accept-Encoding
---EXPECTREGEX--
-^\x1f\x8b\x08.+
+++ /dev/null
---TEST--
-http response cache negative
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-a=b
---ENV--
-HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
-HTTP_IF_NONE_MATCH=0000-00-0000
---FILE--
-<?php
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send();
-?>
---EXPECTHEADERS--
-ETag: "abc"
-Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
---EXPECT--
-<?php
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send();
-?>
+++ /dev/null
---TEST--
-response ranges
---SKIPIF--
-<?php include "skipif.inc"; ?>
---ENV--
-HTTP_RANGE=bytes=2-4
---GET--
-a=b
---FILE--
-<?php
-
-$r = new http\Env\Response;
-$r->setContentType("text/plain");
-$r->setContentDisposition(
- array("attachment" => array(array("filename" => basename(__FILE__))))
-);
-$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
-$r->send();
-
-?>
---EXPECTHEADERS--
-Content-Type: text/plain
---EXPECTF--
-php
+++ /dev/null
---TEST--
-reponse callback
---SKIPIF--
-<?php
-include "skipif.inc";
-if (version_compare(PHP_VERSION, "5.4.0", "<")) die("SKIP 5.3 ob is broken");
-?>
---GET--
-dummy=1
---FILE--
-<?php
-
-$r = new http\Env\Response;
-$r->setCacheControl("public,must-revalidate,max-age=0");
-$r->setThrottleRate(1, 0.1);
-ob_start($r);
-
-echo "foo";
-echo "bar";
-
-ob_end_flush();
-$r->send();
---EXPECTHEADERS--
-Accept-Ranges: bytes
-Cache-Control: public,must-revalidate,max-age=0
-ETag: "9ef61f95"
---EXPECTF--
-foobar
+++ /dev/null
---TEST--
-http response cache positive
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-a=b
---ENV--
-HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:32 GMT
---FILE--
-<?php
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
-$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
-$r->send();
-?>
---EXPECTHEADERS--
-HTTP/1.1 304 Not Modified
-ETag: "abc"
-Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
---EXPECT--
+++ /dev/null
---TEST--
-http response stream
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---FILE--
-<?php
-echo "Test\n";
-
-$f = tmpfile();
-
-$r = new http\Env\Response;
-$r->addHeader("foo", array("bar","baz"));
-$r->getBody()->append("foo");
-
-$r->send($f);
-
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
-Done
---EXPECT--
-Test
-string(77) "HTTP/1.1 200 OK
-Accept-Ranges: bytes
-Foo: bar, baz
-ETag: "8c736521"
-
-foo"
-Done
+++ /dev/null
---TEST--
-response env request
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---GET--
-dummy=1
---FILE--
-<?php
-echo "Test\n";
-
-$tmp = tmpfile();
-
-// modify HTTP env
-$req = new http\Env\Request;
-$req->setHeader("Range", "bytes=2-4");
-
-$res = new http\Env\Response;
-$res->setEnvRequest($req);
-$res->setContentType("text/plain");
-$res->getBody()->append("012345679");
-$res->send($tmp);
-
-rewind($tmp);
-var_dump(stream_get_contents($tmp));
-
-?>
-Done
---EXPECTF--
-Test
-string(%d) "HTTP/1.1 206 Partial Content%c
-Accept-Ranges: bytes%c
-X-Powered-By: %s%c
-Content-Type: text/plain%c
-Content-Range: bytes 2-4/9%c
-%c
-234"
-Done
+++ /dev/null
---TEST--
-env response stream message
---SKIPIF--
-<?php include "skipif.inc"; ?>
---ENV--
-HTTP_ACCEPT_ENCODING=gzip
---FILE--
-<?php
-
-$f = tmpfile();
-
-$r = new http\env\Response;
-$r->setHeader("foo","bar");
-$r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP);
-$r->setBody(new http\message\Body(fopen(__FILE__,"r")));
-$r->send($f);
-
-rewind($f);
-var_dump(stream_get_contents($f));
-
---EXPECTREGEX--
-string\(\d+\) "HTTP\/1\.1 200 OK
-Accept-Ranges: bytes
-Foo: bar
-Content-Encoding: gzip
-Vary: Accept-Encoding
-ETag: "\w+-\w+-\w+"
-Last-Modified: \w+, \d+ \w+ \d{4} \d\d:\d\d:\d\d GMT
-
-\x1f\x8b\x08.+
+++ /dev/null
---TEST--
-http response stream cache negative
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-a=b
---ENV--
-HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT
-HTTP_IF_NONE_MATCH=0000-00-0000
---FILE--
-<?php
-$f = tmpfile();
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
---EXPECTF--
-string(%d) "HTTP/1.1 200 OK%c
-Accept-Ranges: bytes%c
-X-Powered-By: %s%c
-ETag: "abc"%c
-Last-Modified: %s%c
-%c
-<?php
-$f = tmpfile();
-$r = new http\Env\Response;
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
-"
-
+++ /dev/null
---TEST--
-response stream ranges
---SKIPIF--
-<?php include "skipif.inc"; ?>
---ENV--
-HTTP_RANGE=bytes=2-4
---GET--
-a=b
---FILE--
-<?php
-$f = tmpfile();
-$r = new http\Env\Response;
-$r->setContentType("text/plain");
-$r->setContentDisposition(
- array("attachment" => array(array("filename" => basename(__FILE__))))
-);
-$r->setBody(new http\Message\Body(fopen(__FILE__, "rb")));
-$r->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
-?>
---EXPECTF--
-string(%i) "HTTP/1.1 206 Partial Content%c
-Accept-Ranges: bytes%c
-X-Powered-By: PHP/%s%c
-Content-Type: text/plain%c
-Content-Range: bytes 2-4/311%c
-%c
-php"
+++ /dev/null
---TEST--
-http response cache positive with env message
---SKIPIF--
-<?php include "skipif.inc"; ?>
---GET--
-dummy=1
---FILE--
-<?php
-$e = new http\Env\Request;
-$e->setHeader("If-Modified-Since", "Fri, 13 Feb 2009 23:31:32 GMT");
-$r = new http\Env\Response;
-$r->setEnvRequest($e);
-$r->setBody(new http\Message\Body(fopen(__FILE__,"rb")));
-$r->setEtag("abc");
-$r->setLastModified(1234567891);
-$r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n");
-$r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached");
-$r->send();
-?>
---EXPECTHEADERS--
-HTTP/1.1 304 Not Modified
-ETag: "abc"
-Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT
---EXPECT--
+++ /dev/null
---TEST--
-response content disposition
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---GET--
-dummy=1
---FILE--
-<?php
-
-$r = new http\Env\Response;
-$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
-$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
-$r->send();
-
-?>
---EXPECTHEADERS--
-Content-Disposition: attachment;filename=response012.php
---EXPECT--
-<?php
-
-$r = new http\Env\Response;
-$r->setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__))));
-$r->setBody(new http\Message\Body(fopen(__FILE__,"r")));
-$r->send();
-
-?>
-
+++ /dev/null
---TEST--
-response deflate
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---GET--
-dummy=1
---FILE--
-<?php
-
-$req = new http\Env\Request;
-$req->setHeader("Accept-Encoding", "deflate");
-
-$res = new http\Env\Response;
-$res->setCacheControl("public, max-age=3600");
-$res->setContentEncoding(http\Env\Response::CONTENT_ENCODING_GZIP);
-$res->getBody()->append("foobar");
-
-$res->setEnvRequest($req);
-$res->send();
-?>
---EXPECTHEADERS--
-Content-Encoding: deflate
-Vary: Accept-Encoding
-Cache-Control: public, max-age=3600
---EXPECTREGEX--
-^\x78\x9c.+
-
+++ /dev/null
---TEST--
-response invalid ranges
---SKIPIF--
-<?php
-include "skipif.inc";
-?>
---FILE--
-<?php
-$f = tmpfile();
-$req = new http\Env\Request;
-$req->setHeader("Range", "bytes=321-123,123-0");
-$res = new http\Env\Response;
-$res->getBody()->append("foobar");
-$res->setEnvRequest($req);
-$res->send($f);
-rewind($f);
-var_dump(stream_get_contents($f));
---EXPECTF--
-string(96) "HTTP/1.1 416 Requested Range Not Satisfiable
-Accept-Ranges: bytes
-Content-Range: bytes */6
-
-"
-