- improve response performance
authorMichael Wallner <mike@php.net>
Wed, 22 Nov 2006 10:50:11 +0000 (10:50 +0000)
committerMichael Wallner <mike@php.net>
Wed, 22 Nov 2006 10:50:11 +0000 (10:50 +0000)
  . flag streams non-buffered
  . bypass sapi input filter
  . flush explicitly only if throttling is used
- fix tests

25 files changed:
http.c
http_api.c
http_send_api.c
package2.xml
php_http.h
php_http_std_defs.h
tests/HttpResponse_004.phpt
tests/build_url_003.phpt
tests/negotiation_001.phpt
tests/send_data_001.phpt
tests/send_data_002.phpt
tests/send_data_003.phpt
tests/send_data_005.phpt
tests/send_failed_precond_001.phpt
tests/send_file_005.phpt
tests/send_file_009.phpt
tests/send_file_010.phpt
tests/send_file_011.phpt
tests/send_file_013.phpt
tests/send_ifrange_001.phpt
tests/send_ifrange_003.phpt
tests/ut_HttpMessage.phpt [deleted file]
tests/ut_HttpRequest.phpt [deleted file]
tests/ut_HttpRequestPool.phpt [deleted file]
tests/ut_HttpUtil.phpt [deleted file]

diff --git a/http.c b/http.c
index cbc38eb..05f448f 100644 (file)
--- a/http.c
+++ b/http.c
@@ -206,6 +206,10 @@ static inline void _http_globals_free(zend_http_globals *G TSRMLS_DC)
        }
        STR_SET(G->send.content_type, NULL);
        STR_SET(G->send.unquoted_etag, NULL);
+       if (G->server_var) {
+               zval_ptr_dtor(&G->server_var);
+               G->server_var = NULL;
+       }
 }
 /* }}} */
 
index b77dd19..4e304af 100644 (file)
@@ -267,11 +267,26 @@ STATUS _http_check_method_ex(const char *method, const char *methods)
 /* {{{ zval *http_get_server_var_ex(char *, size_t) */
 PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC)
 {
-       zval **hsv;
-       zval **var;
+       zval **hsv, **var;
+       char *env;
+       
+       /* if available, this is a lot faster than accessing $_SERVER */
+       if (sapi_module.getenv) {
+               if ((!(env = sapi_module.getenv((char *) key, key_size TSRMLS_CC))) || (check && !*env)) {
+                       return NULL;
+               }
+               if (HTTP_G->server_var) {
+                       zval_ptr_dtor(&HTTP_G->server_var);
+               }
+               MAKE_STD_ZVAL(HTTP_G->server_var);
+               ZVAL_STRING(HTTP_G->server_var, env, 1);
+               return HTTP_G->server_var;
+       }
+       
 #ifdef ZEND_ENGINE_2
        zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
 #endif
+       
        if ((SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) {
                return NULL;
        }
index 1fe1d4d..ed92028 100644 (file)
 #include "php_http_headers_api.h"
 #include "php_http_send_api.h"
 
+/* {{{ http_flush() */
 #define http_flush(d, l) _http_flush(NULL, (d), (l) TSRMLS_CC)
-/* {{{ static inline void http_flush() */
 static inline void _http_flush(void *nothing, const char *data, size_t data_len TSRMLS_DC)
 {
        PHPWRITE(data, data_len);
-       php_end_ob_buffer(1, 1 TSRMLS_CC);
-       sapi_flush(TSRMLS_C);
-       
-#if 0
-       fprintf(stderr, "Flushing after writing %u bytes\n", (uint) data_len);
-#endif
-       
+       /*      we really only need to flush when throttling is enabled,
+               because we push the data as fast as possible anyway if not */
        if (HTTP_G->send.throttle_delay >= HTTP_DIFFSEC) {
+               if (OG(ob_nesting_level)) {
+                       php_end_ob_buffer(1, 1 TSRMLS_CC);
+               }
+               if (!OG(implicit_flush)) {
+                       sapi_flush(TSRMLS_C);
+               }
                http_sleep(HTTP_G->send.throttle_delay);
        }
 }
@@ -58,6 +59,8 @@ static inline void _http_send_response_start(void **buffer, size_t content_lengt
                                HTTP_DEFLATE_TYPE_GZIP : HTTP_DEFLATE_TYPE_ZLIB);
 #endif
        }
+       /* flush headers */
+       sapi_flush(TSRMLS_C);
 }
 /* }}} */
 
@@ -93,19 +96,20 @@ static inline void _http_send_response_data_plain(void **buffer, const char *dat
 #define http_send_response_data_fetch(b, d, l, m, s, e) _http_send_response_data_fetch((b), (d), (l), (m), (s), (e) TSRMLS_CC)
 static inline void _http_send_response_data_fetch(void **buffer, const void *data, size_t data_len, http_send_mode mode, size_t begin, size_t end TSRMLS_DC)
 {
-       char *buf;
-       long got, len = end - begin;
+       long bsz, got, len = end - begin;
+       
+       if (!(bsz = HTTP_G->send.buffer_size)) {
+               bsz = HTTP_SENDBUF_SIZE;
+       }
        
        switch (mode) {
-               case SEND_RSRC:
-               {
+               case SEND_RSRC: {
                        php_stream *s = (php_stream *) data;
-
                        if (SUCCESS == php_stream_seek(s, begin, SEEK_SET)) {
-                               buf = emalloc(HTTP_SENDBUF_SIZE);
+                               char *buf = emalloc(bsz);
                                
                                while (len > 0) {
-                                       got = php_stream_read(s, buf, MIN(len, HTTP_SENDBUF_SIZE));
+                                       got = php_stream_read(s, buf, MIN(len, bsz));
                                        http_send_response_data_plain(buffer, buf, got);
                                        len -= got;
                                }
@@ -114,20 +118,16 @@ static inline void _http_send_response_data_fetch(void **buffer, const void *dat
                        }
                        break;
                }
-
-               case SEND_DATA:
-               {
-                       buf = (char *) data + begin;
-                       
+               case SEND_DATA: {
+                       const char *buf = data + begin;
                        while (len > 0) {
-                               got = MIN(len, HTTP_SENDBUF_SIZE);
+                               got = MIN(len, bsz);
                                http_send_response_data_plain(buffer, buf, got);
                                len -= got;
                                buf += got;
                        }
                        break;
                }
-
                EMPTY_SWITCH_DEFAULT_CASE();
        }
 }
@@ -507,6 +507,7 @@ PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file, zend_bool close_strea
 {
        STATUS status;
        php_stream_statbuf ssb;
+       int orig_flags;
 
        if ((!file) || php_stream_stat(file, &ssb)) {
                char *defct = sapi_get_default_content_type(TSRMLS_C);
@@ -522,8 +523,11 @@ PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file, zend_bool close_strea
                return FAILURE;
        }
 
+       orig_flags = file->flags;
+       file->flags |= PHP_STREAM_FLAG_NO_BUFFER;
        status = http_send_ex(file, ssb.sb.st_size, SEND_RSRC, no_cache);
-
+       file->flags = orig_flags;
+       
        if (close_stream) {
                php_stream_close(file);
        }
index 684b39d..b49b7dd 100644 (file)
@@ -28,7 +28,7 @@ support. Parallel requests are available for PHP 5 and greater.
   <email>mike@php.net</email>
   <active>yes</active>
  </lead>
- <date>2006-11-05</date>
+ <date>2006-11-22</date>
  <version>
   <release>1.4.0dev</release>
   <api>1.4.0</api>
@@ -39,6 +39,7 @@ support. Parallel requests are available for PHP 5 and greater.
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
+* Improved response performance
 + Added "ipresolve" request option
 + Added HTTP_IPRESOLVE_{ANY|V4|V6}, HttpRequest::IPRESOLVE_{ANY|V4|V6} constants
 + Added missing HTTP_SSL_VERSION_{ANY|TLSv1|SSLv2|SSLv3}, HttpRequest::SSL_VERSION_{ANY|TLSv1|SSLv2|SSLv3} constants
@@ -271,8 +272,6 @@ support. Parallel requests are available for PHP 5 and greater.
     <file role="test" name="stream_filters_001.phpt"/>
     <file role="test" name="stream_filters_002.phpt"/>
     <file role="test" name="stream_filters_003.phpt"/>
-    <file role="test" name="ut_HttpMessage.phpt"/>
-    <file role="test" name="ut_HttpUtil.phpt"/>
    </dir>
   </dir>
  </contents>
index 61fd4c8..f77755a 100644 (file)
@@ -144,6 +144,7 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
 
        zend_bool force_exit;
        zend_bool read_post_data;
+       zval *server_var;
 
 ZEND_END_MODULE_GLOBALS(http)
 
index f851983..0a80180 100644 (file)
@@ -111,7 +111,7 @@ typedef int STATUS;
 #define HTTP_URL_ARGSEP "&"
 
 /* send buffer size */
-#define HTTP_SENDBUF_SIZE 40960
+#define HTTP_SENDBUF_SIZE 8000 /*40960*/
 
 /* CURL buffer size */
 #define HTTP_CURLBUF_SIZE 16384
index 4e6d30c..ffe26c9 100644 (file)
@@ -7,10 +7,11 @@ checkcgi();
 checkmin(5.1);
 skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib support");
 ?>
+--ENV--
+HTTP_IF_NONE_MATCH="900150983cd24fb0d6963f7d28e17f72"
+HTTP_ACCEPT_ENCODING=gzip
 --FILE--
 <?php
-$_SERVER["HTTP_IF_NONE_MATCH"] = '"900150983cd24fb0d6963f7d28e17f72"';
-$_SERVER["HTTP_ACCEPT_ENCODING"] = "gzip";
 HttpResponse::setGzip(true);
 HttpResponse::setCache(true);
 HttpResponse::setCacheControl('public', 3600);
index 6e343a3..cd9c0a3 100644 (file)
@@ -4,9 +4,10 @@ http_build_url()
 <?php
 include 'skip.inc';
 ?>
+--ENV--
+HTTP_HOST=www.example.com
 --FILE--
 <?php
-$_SERVER['HTTP_HOST'] = 'www.example.com';
 $url = '/path/?query#anchor';
 echo "-TEST\n";
 printf("-%s-\n", http_build_url($url));
index df42ff6..d4b13ac 100644 (file)
@@ -4,12 +4,13 @@ negotiation
 <?php
 include 'skip.inc';
 ?>
+--ENV--
+HTTP_ACCEPT=application/xml, application/xhtml+xml, text/html ; q = .8
+HTTP_ACCEPT_LANGUAGE=de-AT,de-DE;q=0.8,en-GB;q=0.3,en-US;q=0.2
+HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7
 --FILE--
 <?php
 echo "-TEST\n";
-$_SERVER['HTTP_ACCEPT'] = 'application/xml, application/xhtml+xml, text/html ; q = .8';
-$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-AT,de-DE;q=0.8,en-GB;q=0.3,en-US;q=0.2';
-$_SERVER['HTTP_ACCEPT_CHARSET'] = 'ISO-8859-1,utf-8;q=0.7,*;q=0.7';
 $langs = array(
        array('de', 'en', 'es'),
 );
index 1cc00de..e5c6840 100644 (file)
@@ -5,9 +5,10 @@ http_send_data() NIL-NUM range
 include 'skip.inc';
 checkcgi();
 ?>
+--ENV--
+HTTP_RANGE=bytes=-5
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=-5';
 http_send_content_type('text/plain');
 http_send_data(str_repeat('123abc', 1000));
 ?>
@@ -19,4 +20,4 @@ Accept-Ranges: bytes
 Content-Range: bytes 5995-5999/6000
 Content-Length: 5
 
-23abc
\ No newline at end of file
+23abc
index 4e8f07b..af7e866 100644 (file)
@@ -5,9 +5,10 @@ http_send_data() NUM-NUM range
 include 'skip.inc';
 checkcgi();
 ?>
+--ENV--
+HTTP_RANGE=bytes=5-6
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=5-6';
 http_send_content_type('text/plain');
 http_send_data(str_repeat('123abc', 1000));
 ?>
@@ -19,4 +20,4 @@ Accept-Ranges: bytes
 Content-Range: bytes 5-6/6000
 Content-Length: 2
 
-c1
\ No newline at end of file
+c1
index 87663fc..c13ec80 100644 (file)
@@ -5,9 +5,10 @@ http_send_data() NUM-NIL range
 include 'skip.inc';
 checkcgi();
 ?>
+--ENV--
+HTTP_RANGE=bytes=5981-
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=5981-';
 http_send_content_type('text/plain');
 http_send_data(str_repeat('123abc', 1000));
 ?>
@@ -19,4 +20,4 @@ Accept-Ranges: bytes
 Content-Range: bytes 5981-5999/6000
 Content-Length: 19
 
-c123abc123abc123abc
\ No newline at end of file
+c123abc123abc123abc
index 286c7e9..28cbb78 100644 (file)
@@ -5,12 +5,13 @@ http_send_data() oversized range
 include 'skip.inc';
 checkcgi();
 ?>
+--ENV--
+HTTP_RANGE=bytes=5990-6000
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=5990-6000';
 http_send_content_type('text/plain');
 http_send_data(str_repeat('123abc', 1000));
 ?>
 --EXPECTF--
 Status: 416
-%s
\ No newline at end of file
+%s
index 6424ecb..dd394e7 100644 (file)
@@ -6,10 +6,11 @@ include 'skip.inc';
 checkcgi();
 checkver(5.1);
 ?>
+--ENV--
+HTTP_RANGE=bytes=0-1
+HTTP_IF_UNMODIFIED_SINCE=Thu, 01 Jan 1970 00:16:40 GMT
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=0-1';
-$_SERVER['HTTP_IF_UNMODIFIED_SINCE'] = http_date(10000);
 http_cache_last_modified();
 http_send_file(__FILE__);
 ?>
index b5287a3..d6705ea 100644 (file)
@@ -5,9 +5,10 @@ http_send_file() multiple ranges
 include 'skip.inc';
 checkcgi();
 ?>
+--ENV--
+HTTP_RANGE=bytes=0-3, 4-5,9-11
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=0-3, 4-5,9-11';
 http_send_content_type('text/plain');
 http_send_file('data.txt');
 ?>
index 3215b03..bc157a9 100644 (file)
@@ -6,9 +6,10 @@ include 'skip.inc';
 checkcgi();
 checkmin(5.1);
 ?>
+--ENV--
+HTTP_RANGE=bytes=5-9
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=5-9';
 http_send_file('data.txt');
 ?>
 --EXPECTF--
index 8ee6eac..20b853a 100644 (file)
@@ -6,9 +6,10 @@ include 'skip.inc';
 checkcgi();
 checkmin(5.1);
 ?>
+--ENV--
+HTTP_RANGE=bytes=-9
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=-9';
 http_send_file('data.txt');
 ?>
 --EXPECTF--
index 1012da4..df6ec60 100644 (file)
@@ -6,9 +6,10 @@ include 'skip.inc';
 checkcgi();
 checkmin(5.1);
 ?>
+--ENV--
+HTTP_RANGE=bytes=1000- 
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=1000- ';
 http_send_file('data.txt');
 ?>
 --EXPECTF--
index 1315488..e97a091 100644 (file)
@@ -6,9 +6,10 @@ include 'skip.inc';
 checkcgi();
 checkmin(5.1);
 ?>
+--ENV--
+HTTP_RANGE=bytes=-1111
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=-1111';
 http_send_file('data.txt');
 ?>
 --EXPECTF--
index 4328226..9b36971 100644 (file)
@@ -5,10 +5,11 @@ http_send() If-Range
 include 'skip.inc';
 checkcgi();
 ?>
+--ENV--
+HTTP_RANGE=bytes=0-1
+HTTP_IF_RANGE="abc"
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=0-1';
-$_SERVER['HTTP_IF_RANGE'] = '"abc"';
 http_cache_etag('abc');
 http_send_file(__FILE__);
 ?>
index 902130f..746d9c7 100644 (file)
@@ -5,10 +5,11 @@ http_send() If-Range
 include 'skip.inc';
 checkcgi();
 ?>
+--ENV--
+HTTP_RANGE=bytes=0-1
+HTTP_IF_RANGE="abcd"
 --FILE--
 <?php
-$_SERVER['HTTP_RANGE'] = 'bytes=0-1';
-$_SERVER['HTTP_IF_RANGE'] = '"abcd"';
 http_cache_etag('abc');
 http_send_file(__FILE__);
 ?>
diff --git a/tests/ut_HttpMessage.phpt b/tests/ut_HttpMessage.phpt
deleted file mode 100644 (file)
index dd36680..0000000
+++ /dev/null
@@ -1,272 +0,0 @@
---TEST--
-PHPUnit HttpMessage
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcls('HttpMessage');
-skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
-?>
---FILE--
-<?php
-echo "-TEST\n";
-
-error_reporting(E_ALL);
-ini_set('html_errors', 0);
-
-require_once 'PHPUnit2/Framework/TestSuite.php';
-require_once 'PHPUnit2/Framework/TestCase.php';
-require_once 'PHPUnit2/TextUI/ResultPrinter.php';
-
-class HttpMessageTest extends PHPUnit2_Framework_TestCase
-{
-    function setUp()
-    {
-        $this->emptyMessage = new HttpMessage;
-        $this->responseMessage = new HttpMessage("HTTP/1.1 302 Found\r\nLocation: /foo\r\nHTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!");
-        $this->requestMessage = new HttpMessage("GET /foo HTTP/1.1\r\nHost: example.com\r\nContent-type: text/plain\r\nContent-length: 10\r\n\r\nHi there!\n");
-    }
-    
-    function test___construct()
-    {
-       $this->assertTrue(new HttpMessage instanceof HttpMessage, "new HttpMessage instanceof HttpMessage");
-    }
-
-    function test_getBody()
-    {
-        $this->assertEquals('', $this->emptyMessage->getBody());
-        $this->assertEquals('Hi there!', $this->responseMessage->getBody());
-        $this->assertEquals("Hi there!\n", $this->requestMessage->getBody());
-    }
-
-    function test_setBody()
-    {
-        $this->emptyMessage->setBody('New Body 1');
-        $this->responseMessage->setBody('New Body 2');
-        $this->requestMessage->setBody('New Body 3');
-        $this->assertEquals('New Body 2', $this->responseMessage->getBody());
-        $this->assertEquals('New Body 1', $this->emptyMessage->getBody());
-        $this->assertEquals('New Body 3', $this->requestMessage->getBody());
-    }
-
-    function test_getHeaders()
-    {
-        $this->assertEquals(array(), $this->emptyMessage->getHeaders());
-        $this->assertEquals(array('Server' => 'Funky/1.0'), $this->responseMessage->getHeaders());
-        $this->assertEquals(array('Host' => 'example.com', 'Content-Type' => 'text/plain', 'Content-Length' => '10'), $this->requestMessage->getHeaders());
-    }
-
-    function test_setHeaders()
-    {
-        $this->emptyMessage->setHeaders(array('Foo' => 'Bar'));
-        $this->responseMessage->setHeaders(array());
-        $this->requestMessage->setHeaders(array('Host' => 'www.example.com'));
-        $this->assertEquals(array('Foo' => 'Bar'), $this->emptyMessage->getHeaders());
-        $this->assertEquals(array(), $this->responseMessage->getHeaders());
-        $this->assertEquals(array('Host' => 'www.example.com'), $this->requestMessage->getHeaders());
-    }
-
-    function test_addHeaders()
-    {
-        $this->emptyMessage->addHeaders(array('Foo' => 'Bar'));
-        $this->responseMessage->addHeaders(array('Date' => 'today'));
-        $this->requestMessage->addHeaders(array('Host' => 'www.example.com'));
-        $this->assertEquals(array('Foo' => 'Bar'), $this->emptyMessage->getHeaders());
-        $this->assertEquals(array('Server' => 'Funky/1.0', 'Date' => 'today'), $this->responseMessage->getHeaders());
-        $this->assertEquals(array('Host' => 'www.example.com', 'Content-Type' => 'text/plain', 'Content-Length' => '10'), $this->requestMessage->getHeaders());
-        $this->emptyMessage->addHeaders(array('Foo' => 'Baz'), true);
-        $this->assertEquals(array('Foo' => array('Bar', 'Baz')), $this->emptyMessage->getHeaders());
-    }
-
-    function test_getType()
-    {
-        $this->assertEquals(HTTP_MSG_NONE, $this->emptyMessage->getType());
-        $this->assertEquals(HTTP_MSG_RESPONSE, $this->responseMessage->getType());
-        $this->assertEquals(HTTP_MSG_REQUEST, $this->requestMessage->getType());
-    }
-
-    function test_setType()
-    {
-        $this->emptyMessage->setType(HTTP_MSG_RESPONSE);
-        $this->responseMessage->setType(HTTP_MSG_REQUEST);
-        $this->requestMessage->setType(HTTP_MSG_NONE);
-        $this->assertEquals(HTTP_MSG_RESPONSE, $this->emptyMessage->getType());
-        $this->assertEquals(HTTP_MSG_REQUEST, $this->responseMessage->getType());
-        $this->assertEquals(HTTP_MSG_NONE, $this->requestMessage->getType());
-    }
-
-    function test_getResponseCode()
-    {
-        $this->assertFalse($this->emptyMessage->getResponseCode());
-        $this->assertEquals(200, $this->responseMessage->getResponseCode());
-        $this->assertFalse($this->requestMessage->getResponseCode());
-    }
-
-    function test_setResponseCode()
-    {
-        $this->assertFalse($this->emptyMessage->setResponseCode(301));
-        $this->assertTrue($this->responseMessage->setResponseCode(301));
-        $this->assertFalse($this->requestMessage->setResponseCode(301));
-        $this->assertFalse($this->emptyMessage->getResponseCode());
-        $this->assertEquals(301, $this->responseMessage->getResponseCode());
-        $this->assertFalse($this->requestMessage->getResponseCode());
-    }
-
-    function test_getRequestMethod()
-    {
-        $this->assertFalse($this->emptyMessage->getRequestMethod());
-        $this->assertFalse($this->responseMessage->getRequestMethod());
-        $this->assertEquals('GET', $this->requestMessage->getRequestMethod());
-    }
-
-    function test_setRequestMethod()
-    {
-        $this->assertFalse($this->emptyMessage->setRequestMethod('POST'));
-        $this->assertFalse($this->responseMessage->setRequestMethod('POST'));
-        $this->assertTrue($this->requestMessage->setRequestMethod('POST'));
-        $this->assertFalse($this->emptyMessage->getRequestMethod());
-        $this->assertFalse($this->responseMessage->getRequestMethod());
-        $this->assertEquals('POST', $this->requestMessage->getRequestMethod());
-    }
-
-    function test_getRequestUrl()
-    {
-        $this->assertFalse($this->emptyMessage->getRequestUrl());
-        $this->assertFalse($this->responseMessage->getRequestUrl());
-        $this->assertEquals('/foo', $this->requestMessage->getRequestUrl());
-    }
-
-    function test_setRequestUrl()
-    {
-        $this->assertFalse($this->emptyMessage->setRequestUrl('/bla'));
-        $this->assertFalse($this->responseMessage->setRequestUrl('/bla'));
-        $this->assertTrue($this->requestMessage->setRequestUrl('/bla'));
-        $this->assertFalse($this->emptyMessage->getRequestUrl());
-        $this->assertFalse($this->responseMessage->getRequestUrl());
-        $this->assertEquals('/bla', $this->requestMessage->getRequestUrl());
-    }
-
-    function test_getHttpVersion()
-    {
-        $this->assertEquals('0.0', $this->emptyMessage->getHttpVersion());
-        $this->assertEquals('1.1', $this->responseMessage->getHttpVersion());
-        $this->assertEquals('1.1', $this->requestMessage->getHttpVersion());
-    }
-
-    function test_setHttpVersion()
-    {
-        $this->assertTrue($this->emptyMessage->setHttpVersion(1.0));
-        $this->assertTrue($this->responseMessage->setHttpVersion(1.0));
-        $this->assertTrue($this->requestMessage->setHttpVersion(1.0));
-        $this->assertEquals('1.0', $this->emptyMessage->getHttpVersion());
-        $this->assertEquals('1.0', $this->responseMessage->getHttpVersion());
-        $this->assertEquals('1.0', $this->requestMessage->getHttpVersion());
-    }
-
-    function test_getParentMessage()
-    {
-        $this->assertTrue($this->responseMessage->getParentMessage() instanceOf HttpMessage);
-        try {
-            $this->requestMessage->getParentMessage();
-            $this->assertTrue(false, "\$this->requestMessage->getParentMessage() did not throw an exception");
-        } catch (HttpRuntimeException $ex) {
-        }
-    }
-
-    function test_send()
-    {
-    }
-
-    function test_toString()
-    {
-        $this->assertEquals('', $this->emptyMessage->toString());
-        $this->assertEquals("HTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!\r\n", $this->responseMessage->toString());
-        $this->assertEquals("GET /foo HTTP/1.1\r\nHost: example.com\r\nContent-Type: text/plain\r\nContent-Length: 10\r\n\r\nHi there!\n\r\n", $this->requestMessage->toString());
-    }
-
-    function test_count()
-    {
-        if (5.1 <= (float)PHP_VERSION) {
-            $this->assertEquals(1, count($this->emptyMessage));
-            $this->assertEquals(2, count($this->responseMessage));
-            $this->assertEquals(1, count($this->requestMessage));
-        } else {
-            $this->assertEquals(1, $this->emptyMessage->count());
-            $this->assertEquals(2, $this->responseMessage->count());
-            $this->assertEquals(1, $this->requestMessage->count());
-        }
-    }
-
-    function test_serialize()
-    {
-    }
-
-    function test_unserialize()
-    {
-    }
-
-    function test___toString()
-    {
-        ob_start();
-        echo $this->responseMessage;
-        $this->assertEquals("HTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!\r\n", ob_get_clean());
-    }
-
-    function test_fromString()
-    {
-        $msg = HttpMessage::fromString("HTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!");
-        $this->assertTrue($msg instanceOf HttpMessage);
-        $this->assertEquals(HTTP_MSG_RESPONSE, $msg->getType());
-        $this->assertEquals("Hi there!", $msg->getBody());
-    }
-}
-
-$s = new PHPUnit2_Framework_TestSuite('HttpMessageTest');
-$p = new PHPUnit2_TextUI_ResultPrinter();
-$p->printResult($s->run(), 0);
-
-echo "Done\n";
-?>
---EXPECTF--
-%sTEST
-
-Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::setResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::setResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::setRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::setRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestUrl(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestUrl(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::setRequestUrl(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::setRequestUrl(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestUrl(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-Notice: HttpMessage::getRequestUrl(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
-
-
-Time: 0
-
-OK (24 tests)
-Done
diff --git a/tests/ut_HttpRequest.phpt b/tests/ut_HttpRequest.phpt
deleted file mode 100644 (file)
index 3b69c2a..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
---TEST--
-PHPUnit HttpRequest
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcls('HttpRequest');
-skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
-?>
---FILE--
-<?php
-echo "-TEST\n";
-
-error_reporting(E_ALL);
-ini_set('html_errors', 0);
-
-require_once 'PHPUnit2/Framework/TestSuite.php';
-require_once 'PHPUnit2/Framework/TestCase.php';
-require_once 'PHPUnit2/TextUI/ResultPrinter.php';
-
-class HttpRequestTest extends PHPUnit2_Framework_TestCase
-{
-    function test___construct()
-    {
-    }
-
-    function test___destruct()
-    {
-    }
-
-    function test_setOptions()
-    {
-    }
-
-    function test_getOptions()
-    {
-    }
-
-    function test_setSslOptions()
-    {
-    }
-
-    function test_getSslOptions()
-    {
-    }
-
-    function test_addHeaders()
-    {
-    }
-
-    function test_getHeaders()
-    {
-    }
-
-    function test_setHeaders()
-    {
-    }
-
-    function test_addCookies()
-    {
-    }
-
-    function test_getCookies()
-    {
-    }
-
-    function test_setCookies()
-    {
-    }
-
-    function test_setMethod()
-    {
-    }
-
-    function test_getMethod()
-    {
-    }
-
-    function test_setUrl()
-    {
-    }
-
-    function test_getUrl()
-    {
-    }
-
-    function test_setContentType()
-    {
-    }
-
-    function test_getContentType()
-    {
-    }
-
-    function test_setQueryData()
-    {
-    }
-
-    function test_getQueryData()
-    {
-    }
-
-    function test_addQueryData()
-    {
-    }
-
-    function test_setPostFields()
-    {
-    }
-
-    function test_getPostFields()
-    {
-    }
-
-    function test_addPostFields()
-    {
-    }
-
-    function test_setRawPostData()
-    {
-    }
-
-    function test_getRawPostData()
-    {
-    }
-
-    function test_addRawPostData()
-    {
-    }
-
-    function test_setPostFiles()
-    {
-    }
-
-    function test_addPostFile()
-    {
-    }
-
-    function test_getPostFiles()
-    {
-    }
-
-    function test_setPutFile()
-    {
-    }
-
-    function test_getPutFile()
-    {
-    }
-
-    function test_send()
-    {
-    }
-
-    function test_getResponseData()
-    {
-    }
-
-    function test_getResponseHeader()
-    {
-    }
-
-    function test_getResponseCookie()
-    {
-    }
-
-    function test_getResponseCode()
-    {
-    }
-
-    function test_getResponseBody()
-    {
-    }
-
-    function test_getResponseInfo()
-    {
-    }
-
-    function test_getResponseMessage()
-    {
-    }
-
-    function test_getRequestMessage()
-    {
-    }
-
-    function test_getHistory()
-    {
-    }
-
-    function test_clearHistory()
-    {
-    }
-
-    function test_get()
-    {
-    }
-
-    function test_head()
-    {
-    }
-
-    function test_postData()
-    {
-    }
-
-    function test_postFields()
-    {
-    }
-
-    function test_putFile()
-    {
-    }
-
-    function test_putStream()
-    {
-    }
-
-    function test_methodRegister()
-    {
-    }
-
-    function test_methodUnregister()
-    {
-    }
-
-    function test_methodName()
-    {
-    }
-
-    function test_methodExists()
-    {
-    }
-
-
-}
-
-$s = new PHPUnit2_Framework_TestSuite('HttpRequestTest');
-$p = new PHPUnit2_TextUI_ResultPrinter();
-$p->printResult($s->run(), 0);
-
-echo "Done\n";
-?>
---EXPECTF--
-%sTEST
-
-
-Time: 0
-
-OK (53 tests)
-Done
diff --git a/tests/ut_HttpRequestPool.phpt b/tests/ut_HttpRequestPool.phpt
deleted file mode 100644 (file)
index 1d82a63..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
---TEST--
-PHPUnit HttpRequestPool
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcls('HttpRequestPool');
-skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
-?>
---FILE--
-<?php
-echo "-TEST\n";
-
-error_reporting(E_ALL);
-ini_set('html_errors', 0);
-
-require_once 'PHPUnit2/Framework/TestSuite.php';
-require_once 'PHPUnit2/Framework/TestCase.php';
-require_once 'PHPUnit2/TextUI/ResultPrinter.php';
-
-class HttpRequestPoolTest extends PHPUnit2_Framework_TestCase
-{
-    function test___construct()
-    {
-    }
-
-    function test___destruct()
-    {
-    }
-
-    function test_attach()
-    {
-    }
-
-    function test_detach()
-    {
-    }
-
-    function test_send()
-    {
-    }
-
-    function test_reset()
-    {
-    }
-
-    function test_socketPerform()
-    {
-    }
-
-    function test_socketSelect()
-    {
-    }
-
-    function test_valid()
-    {
-    }
-
-    function test_current()
-    {
-    }
-
-    function test_key()
-    {
-    }
-
-    function test_next()
-    {
-    }
-
-    function test_rewind()
-    {
-    }
-
-    function test_count()
-    {
-    }
-
-    function test_getAttachedRequests()
-    {
-    }
-
-    function test_getFinishedRequests()
-    {
-    }
-
-
-}
-
-$s = new PHPUnit2_Framework_TestSuite('HttpRequestPoolTest');
-$p = new PHPUnit2_TextUI_ResultPrinter();
-$p->printResult($s->run(), 0);
-
-echo "Done\n";
-?>
---EXPECTF--
-%sTEST
-
-
-Time: 0
-
-OK (16 tests)
-Done
diff --git a/tests/ut_HttpUtil.phpt b/tests/ut_HttpUtil.phpt
deleted file mode 100644 (file)
index 6bf6e2e..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
---TEST--
-PHPUnit HttpUtil
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcls('HttpUtil');
-skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
-?>
---FILE--
-<?php
-echo "-TEST\n";
-
-error_reporting(E_ALL);
-ini_set('html_errors', 0);
-
-require_once 'PHPUnit2/Framework/TestSuite.php';
-require_once 'PHPUnit2/Framework/TestCase.php';
-require_once 'PHPUnit2/TextUI/ResultPrinter.php';
-
-class HttpUtilTest extends PHPUnit2_Framework_TestCase
-{
-    function test_date()
-    {
-       $this->assertEquals('Thu, 01 Jan 1970 00:00:01 GMT', HttpUtil::date(1));
-    }
-
-    function test_buildUrl()
-    {
-       $_SERVER['SERVER_NAME'] = 'www.example.com';
-       $this->assertEquals('http://www.example.com/test.php?foo=bar', HttpUtil::buildUrl('/test.php?foo=bar', array('port' => 80)));
-       $this->assertEquals('https://www.example.com/', HttpUtil::buildUrl('/', array('scheme' => 'https')));
-       $this->assertEquals('ftp://ftp.example.com/pub', HttpUtil::buildUrl('/pub', array('host' => 'ftp.example.com', 'port' => 21)));
-    }
-
-    function test_negotiateLanguage()
-    {
-       $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en, de;q=0.5, it-IT; q = 0.5   ';
-       $this->assertEquals('de', HttpUtil::negotiateLanguage(array('de','it'), $r));
-       $this->assertEquals(array('de'=>0.5,'it'=>0.45), $r);
-    }
-
-    function test_negotiateCharset()
-    {
-       $_SERVER['HTTP_ACCEPT_CHARSET'] = '  iso-8859-1, Unicode ;q=0 , utf-8  ';
-       $this->assertEquals('iso-8859-1', HttpUtil::negotiateCharset(array('utf-8','iso-8859-1'), $r));
-       $this->assertEquals(array('iso-8859-1'=>1000.0,'utf-8'=>999.0), $r);
-    }
-
-    function test_negotiateContentType()
-    {
-       $_SERVER['HTTP_ACCEPT'] = ' text/xml+xhtml, text/html;q = .9,  *';
-       $this->assertEquals('text/xml+xhtml', HttpUtil::negotiateContentType(array('text/xml+xhtml', 'text/html'), $r));
-       $this->assertEquals(array('text/xml+xhtml'=>1000.0,'text/html'=>0.9), $r);
-    }
-
-    function test_matchModified()
-    {
-       $_SERVER['HTTP_IF_MODIFIED_SINCE'] = 'Fri, 02 Jan 1970 00:00:01 GMT';
-       $this->assertTrue(HttpUtil::matchModified(1));
-       $this->assertFalse(HttpUtil::matchModified(2*24*60*60+1));
-       unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
-       
-       $_SERVER['HTTP_IF_UNMODIFIED_SINCE'] = 'Fri, 02 Jan 1970 00:00:01 GMT';
-       $this->assertTrue(HttpUtil::matchModified(1, true));
-       $this->assertFalse(HttpUtil::matchModified(2*24*60*60+1, true));
-       unset($_SERVER['HTTP_IF_UNMODIFIED_SINCE']);
-    }
-
-    function test_matchEtag()
-    {
-       $_SERVER['HTTP_IF_NONE_MATCH'] = '"abc"';
-       $this->assertTrue(HttpUtil::matchEtag('abc'));
-       $this->assertFalse(HttpUtil::matchEtag('ABC'));
-       unset($_SERVER['HTTP_IF_NONE_MATCH']);
-       
-       $_SERVER['HTTP_IF_MATCH'] = '"abc"';
-       $this->assertTrue(HttpUtil::matchEtag('abc', true));
-       $this->assertFalse(HttpUtil::matchEtag('ABC', true));
-       unset($_SERVER['HTTP_IF_MATCH']);
-       
-       $_SERVER['HTTP_IF_NONE_MATCH'] = '*';
-       $this->assertTrue(HttpUtil::matchEtag('abc'));
-       $this->assertTrue(HttpUtil::matchEtag('ABC'));
-       unset($_SERVER['HTTP_IF_NONE_MATCH']);
-       
-       $_SERVER['HTTP_IF_MATCH'] = '*';
-       $this->assertTrue(HttpUtil::matchEtag('abc', true));
-       $this->assertTrue(HttpUtil::matchEtag('ABC', true));
-       unset($_SERVER['HTTP_IF_MATCH']);
-    }
-
-    function test_matchRequestHeader()
-    {
-       $_SERVER['HTTP_FOO'] = 'FoObAr';
-       $this->assertTrue(HttpUtil::matchRequestHeader('foo', 'foobar', false));
-       $this->assertTrue(HttpUtil::matchRequestHeader('foo', 'FoObAr', true));
-       $this->assertFalse(HttpUtil::matchRequestHeader('foo', 'foobar', true));
-    }
-    
-    function test_zlib()
-    {
-       if ($support = http_support(HTTP_SUPPORT_ENCODINGS)) {
-               $this->assertEquals(file_get_contents(__FILE__), http_inflate(http_deflate(file_get_contents(__FILE__), HTTP_DEFLATE_TYPE_GZIP)));
-               $this->assertEquals(file_get_contents(__FILE__), http_inflate(http_deflate(file_get_contents(__FILE__))));
-               } else {
-                       $this->assertFalse($support);
-               }
-       }
-}
-
-$s = new PHPUnit2_Framework_TestSuite('HttpUtilTest');
-$p = new PHPUnit2_TextUI_ResultPrinter();
-$p->printResult($s->run(), 0);
-
-echo "Done\n";
-?>
---EXPECTF--
-%sTEST
-
-
-Time: 0
-
-OK (9 tests)
-Done