- fix usage of request time
authorMichael Wallner <mike@php.net>
Sat, 27 May 2006 17:20:09 +0000 (17:20 +0000)
committerMichael Wallner <mike@php.net>
Sat, 27 May 2006 17:20:09 +0000 (17:20 +0000)
- fixup tests

27 files changed:
http.c
http_api.c
http_cache_api.c
http_functions.c
http_request_api.c
http_request_method_api.c
http_send_api.c
php_http.h
tests/INI_001.phpt [deleted file]
tests/allowed_methods_001.phpt
tests/allowed_methods_002.phpt
tests/etag_mode_001.phpt
tests/etag_mode_002.phpt
tests/etag_mode_003.phpt
tests/etag_mode_004.phpt
tests/etag_mode_011.phpt
tests/etag_mode_012.phpt
tests/etag_mode_013.phpt
tests/etag_mode_014.phpt
tests/etag_mode_031.phpt
tests/etag_mode_032.phpt
tests/etag_mode_033.phpt
tests/etag_mode_034.phpt
tests/etag_mode_041.phpt
tests/etag_mode_042.phpt
tests/etag_mode_043.phpt
tests/etag_mode_044.phpt

diff --git a/http.c b/http.c
index 9eb59b9..1d33864 100644 (file)
--- a/http.c
+++ b/http.c
@@ -183,10 +183,12 @@ static void http_globals_init_once(zend_http_globals *G)
 #define http_globals_init(g) _http_globals_init((g) TSRMLS_CC)
 static inline void _http_globals_init(zend_http_globals *G TSRMLS_DC)
 {
-       G->send.buffer_size = HTTP_SENDBUF_SIZE;
-#ifndef HTTP_HAVE_SAPI_RTIME
-       G->request_time = time(NULL);
+#ifdef HTTP_HAVE_SAPI_RTIME
+       G->request.time = Z_LVAL_P(http_get_server_var("REQUEST_TIME"));
+#else
+       G->request.time = time(NULL);
 #endif
+       G->send.buffer_size = HTTP_SENDBUF_SIZE;
        G->read_post_data = 0;
 }
 
index 2254208..db8f46c 100644 (file)
@@ -116,7 +116,7 @@ void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC)
        struct tm nowtm;
        char datetime[20] = {0};
        
-       now = HTTP_GET_REQUEST_TIME();
+       now = HTTP_G->request.time;
        strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
 
 #define HTTP_LOG_WRITE(file, type, msg) \
@@ -208,10 +208,10 @@ PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zen
        if ((SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) {
                return NULL;
        }
-       if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void *) &var)) || (Z_TYPE_PP(var) != IS_STRING)) {
+       if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void *) &var))) {
                return NULL;
        }
-       if (check && !(Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
+       if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
                return NULL;
        }
        return *var;
index 7c748cc..9a6ea89 100644 (file)
@@ -64,7 +64,7 @@ PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode dat
        php_stream_statbuf ssb;
 
        switch (data_mode) {
-               case SEND_DATA: return HTTP_GET_REQUEST_TIME();
+               case SEND_DATA: return HTTP_G->request.time;
                case SEND_RSRC: return php_stream_stat((php_stream *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime;
                default:                return php_stream_stat_path((char *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime;
        }
index e894b19..ad220d3 100644 (file)
@@ -55,7 +55,7 @@ PHP_FUNCTION(http_date)
        }
 
        if (t == -1) {
-               t = (long) HTTP_GET_REQUEST_TIME();
+               t = HTTP_G->request.time;
        }
 
        RETURN_STRING(http_date(t), 0);
@@ -430,7 +430,7 @@ PHP_FUNCTION(http_send_last_modified)
        }
 
        if (t == -1) {
-               t = (long) HTTP_GET_REQUEST_TIME();
+               t = HTTP_G->request.time;
        }
 
        RETURN_SUCCESS(http_send_last_modified(t));
@@ -510,7 +510,7 @@ PHP_FUNCTION(http_match_modified)
 
        // current time if not supplied (senseless though)
        if (t == -1) {
-               t = (long) HTTP_GET_REQUEST_TIME();
+               t = HTTP_G->request.time;
        }
 
        if (for_range) {
@@ -578,7 +578,7 @@ PHP_FUNCTION(http_cache_last_modified)
        
        HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
 
-       t = (long) HTTP_GET_REQUEST_TIME();
+       t = HTTP_G->request.time;
 
        /* 0 or omitted */
        if (!last_modified) {
@@ -605,7 +605,7 @@ PHP_FUNCTION(http_cache_last_modified)
 /* {{{ proto bool http_cache_etag([string etag])
  *
  * Attempts to cache the sent entity by its ETag, either supplied or generated 
- * by the hash algorithm specified by the INI setting "http.etag_mode".
+ * by the hash algorithm specified by the INI setting "http.etag.mode".
  *
  * If the clients "If-None-Match" header matches the supplied/calculated
  * ETag, the body is considered cached on the clients side and
@@ -634,7 +634,7 @@ PHP_FUNCTION(http_cache_etag)
 /* {{{ proto string ob_etaghandler(string data, int mode)
  *
  * For use with ob_start().  Output buffer handler generating an ETag with
- * the hash algorithm specified with the INI setting "http.etag_mode".
+ * the hash algorithm specified with the INI setting "http.etag.mode".
  */
 PHP_FUNCTION(ob_etaghandler)
 {
index b59d943..7bb54a8 100644 (file)
@@ -745,7 +745,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                        if (Z_LVAL_P(zoption) > 0) {
                                HTTP_CURL_OPT(CURLOPT_TIMEVALUE, Z_LVAL_P(zoption));
                        } else {
-                               HTTP_CURL_OPT(CURLOPT_TIMEVALUE, (long) HTTP_GET_REQUEST_TIME() + Z_LVAL_P(zoption));
+                               HTTP_CURL_OPT(CURLOPT_TIMEVALUE, (long) HTTP_G->request.time + Z_LVAL_P(zoption));
                        }
                        HTTP_CURL_OPT(CURLOPT_TIMECONDITION, (long) (range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE));
                } else {
index 9e428d1..3359b28 100644 (file)
@@ -109,7 +109,7 @@ PHP_RINIT_FUNCTION(http_request_method)
                zval **data;
        
                zend_hash_init(&methods, 0, NULL, ZVAL_PTR_DTOR, 0);
-               http_parse_params(HTTP_G->request.methods.custom.ini, &methods);
+               http_parse_params(HTTP_G->request.methods.custom.ini, HTTP_PARAMS_DEFAULT, &methods);
                FOREACH_HASH_VAL(pos, &methods, data) {
                        if (Z_TYPE_PP(data) == IS_STRING) {
                                http_request_method_register(Z_STRVAL_PP(data), Z_STRLEN_PP(data));
index 10b02f6..1a77652 100644 (file)
@@ -366,7 +366,7 @@ PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_s
                                char boundary_str[32], range_header_str[256];
                                size_t boundary_len, range_header_len;
                                
-                               boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) HTTP_GET_REQUEST_TIME(), (float) php_combined_lcg(TSRMLS_C));
+                               boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) HTTP_G->request.time, (float) php_combined_lcg(TSRMLS_C));
                                range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Type: multipart/byteranges; boundary=%s", boundary_str);
                                
                                http_send_status_header_ex(206, range_header_str, range_header_len, 1);
index 4e2a7c6..6c378a2 100644 (file)
@@ -33,9 +33,7 @@
 #ifdef HTTP_WANT_SAPI
 #      if PHP_API_VERSION > 20041225
 #              define HTTP_HAVE_SAPI_RTIME
-#              define HTTP_GET_REQUEST_TIME() sapi_get_request_time(TSRMLS_C)
 #      else
-#              define HTTP_GET_REQUEST_TIME() HTTP_G->request_time
 #      endif
 #      include "SAPI.h"
 #endif
@@ -115,6 +113,7 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
        } send;
 
        struct _http_globals_request {
+               time_t time;
                struct _http_globals_request_methods {
                        char *allowed;
                        struct _http_globals_request_methods_custom {
@@ -125,9 +124,6 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
                } methods;
        } request;
 
-#ifndef HTTP_HAVE_SAPI_RTIME
-       time_t request_time;
-#endif
 #ifdef ZEND_ENGINE_2
        zend_bool only_exceptions;
 #endif
diff --git a/tests/INI_001.phpt b/tests/INI_001.phpt
deleted file mode 100644 (file)
index 9210aad..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-INI entries
---SKIPIF--
-<?php
-include 'skip.inc';
-?>
---FILE--
-<?php
-echo "-TEST\n";
-ini_set('http.cache_log', 'cache.log');
-var_dump(ini_get('http.cache_log'));
-ini_set('http.allowed_methods', 'POST, HEAD, GET');
-var_dump(ini_get('http.allowed_methods'));
-ini_set('http.only_exceptions', true);
-var_dump(ini_get('http.only_exceptions'));
-echo "Done\n";
-?>
---EXPECTF--
-%sTEST
-string(9) "cache.log"
-string(15) "POST, HEAD, GET"
-string(1) "1"
-Done
-
index b7e3ba5..e0940b3 100644 (file)
@@ -10,7 +10,7 @@ checkmax(5.0);
 <?php
 include 'log.inc';
 log_prepare(_AMETH_LOG);
-ini_set('http.allowed_methods', 'POST');
+ini_set('http.request.methods.allowed', 'POST');
 echo "Done\n";
 ?>
 --EXPECTF--
index 2185d8b..800a805 100644 (file)
@@ -10,7 +10,7 @@ checkmin(5.1);
 <?php
 include 'log.inc';
 log_prepare(_AMETH_LOG);
-ini_set('http.allowed_methods', 'POST');
+ini_set('http.request.methods.allowed', 'POST');
 echo "Done\n";
 ?>
 --EXPECTF--
index 5acd930..809efee 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'crc32');
+ini_set('http.etag.mode', 'crc32');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 5ca8d8f..3312f32 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha1');
+ini_set('http.etag.mode', 'sha1');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 0b98f9f..fd67461 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'md5');
+ini_set('http.etag.mode', 'md5');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index cd56bae..5ec9f22 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 205b60a..1d6f039 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'crc32');
+ini_set('http.etag.mode', 'crc32');
 http_cache_etag();
 print("abc\n");
 ?>
index 5a8702e..1e4d779 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha1');
+ini_set('http.etag.mode', 'sha1');
 http_cache_etag();
 print("abc\n");
 ?>
index 919d34e..3c354f8 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'md5');
+ini_set('http.etag.mode', 'md5');
 http_cache_etag();
 print("abc\n");
 ?>
index c6f1731..bcdefca 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 print("abc\n");
 ?>
index a7d02f1..813b309 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', extension_loaded('hash')?'crc32b':'crc32');
+ini_set('http.etag.mode', extension_loaded('hash')?'crc32b':'crc32');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 71ae9d3..8757118 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'SHA1');
+ini_set('http.etag.mode', 'SHA1');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index f72b524..3f75c16 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'MD5');
+ini_set('http.etag.mode', 'MD5');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index bc9d311..bce9e52 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index e367de8..694608e 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', extension_loaded('hash')?'crc32b':'crc32');
+ini_set('http.etag.mode', extension_loaded('hash')?'crc32b':'crc32');
 http_cache_etag();
 print("abc\n");
 ?>
index 5c77db4..59d7f42 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'SHA1');
+ini_set('http.etag.mode', 'SHA1');
 http_cache_etag();
 print("abc\n");
 ?>
index dbb5438..065bc93 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'bogus');
+ini_set('http.etag.mode', 'bogus');
 http_cache_etag();
 print("abc\n");
 ?>
index 055395a..0d8129a 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 print("abc\n");
 ?>