- API juggling
authorMichael Wallner <mike@php.net>
Sun, 24 Jul 2005 08:51:41 +0000 (08:51 +0000)
committerMichael Wallner <mike@php.net>
Sun, 24 Jul 2005 08:51:41 +0000 (08:51 +0000)
- make tests -which can- working with CLI and CGI

15 files changed:
http_request_object.c
http_response_object.c
http_util_object.c
php_http_request_object.h
php_http_response_object.h
php_http_util_object.h
tests/HttpMessage_001.phpt
tests/HttpRequest_001.phpt
tests/abs_uri_001.phpt
tests/abs_uri_002.phpt
tests/chunked_decode_001.phpt
tests/date_001.phpt
tests/date_002.phpt
tests/parse_headers_001.phpt
tests/split_response_001.phpt

index 4fcddabcb82d37c8cd8706f5a2d17bd0c282c60b..4d862279e0807a13b05cb45cea093fc2bad16902 100644 (file)
@@ -27,6 +27,7 @@
 #include "php_http_request_object.h"
 #include "php_http_request_api.h"
 #include "php_http_request_pool_api.h"
+#include "php_http.h"
 #include "php_http_api.h"
 #include "php_http_url_api.h"
 #include "php_http_message_api.h"
@@ -41,6 +42,7 @@
 #define HTTP_BEGIN_ARGS(method, ret_ref, req_args)     HTTP_BEGIN_ARGS_EX(HttpRequest, method, ret_ref, req_args)
 #define HTTP_EMPTY_ARGS(method, ret_ref)                       HTTP_EMPTY_ARGS_EX(HttpRequest, method, ret_ref)
 #define HTTP_REQUEST_ME(method, visibility)                    PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
+#define HTTP_REQUEST_ALIAS(method, func)                       HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
 
 HTTP_EMPTY_ARGS(__destruct, 0);
 HTTP_BEGIN_ARGS(__construct, 0, 0)
@@ -143,6 +145,62 @@ HTTP_END_ARGS;
 HTTP_EMPTY_ARGS(getResponseMessage, 1);
 HTTP_EMPTY_ARGS(send, 0);
 
+HTTP_BEGIN_ARGS(get, 1, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(options, 0)
+       HTTP_ARG_VAL(info, 1)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(head, 1, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(options, 0)
+       HTTP_ARG_VAL(info, 1)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(postData, 2, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(data, 0)
+       HTTP_ARG_VAL(options, 0)
+       HTTP_ARG_VAL(info, 1)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(postFields, 2, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(data, 0)
+       HTTP_ARG_VAL(options, 0)
+       HTTP_ARG_VAL(info, 1)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(putFile, 2, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(file, 0)
+       HTTP_ARG_VAL(options, 0)
+       HTTP_ARG_VAL(info, 1)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(putStream, 2, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(stream, 0)
+       HTTP_ARG_VAL(options, 0)
+       HTTP_ARG_VAL(info, 1)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(methodRegister, 1, 0)
+       HTTP_ARG_VAL(method_name, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(methodUnregister, 1, 0)
+       HTTP_ARG_VAL(method, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(methodName, 1, 0)
+       HTTP_ARG_VAL(method_id, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(methodExists, 1, 0)
+       HTTP_ARG_VAL(method, 0)
+HTTP_END_ARGS;
+
 #define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C)
 static inline void _http_request_object_declare_default_properties(TSRMLS_D);
 
@@ -203,6 +261,18 @@ zend_function_entry http_request_object_fe[] = {
        HTTP_REQUEST_ME(getResponseInfo, ZEND_ACC_PUBLIC)
        HTTP_REQUEST_ME(getResponseMessage, ZEND_ACC_PUBLIC)
 
+       HTTP_REQUEST_ALIAS(get, http_get)
+       HTTP_REQUEST_ALIAS(head, http_head)
+       HTTP_REQUEST_ALIAS(postData, http_post_data)
+       HTTP_REQUEST_ALIAS(postFields, http_post_fields)
+       HTTP_REQUEST_ALIAS(putFile, http_put_file)
+       HTTP_REQUEST_ALIAS(putStream, http_put_stream)
+
+       HTTP_REQUEST_ALIAS(methodRegister, http_request_method_register)
+       HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister)
+       HTTP_REQUEST_ALIAS(methodName, http_request_method_name)
+       HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists)
+
        {NULL, NULL, NULL}
 };
 static zend_object_handlers http_request_object_handlers;
index f7cb216c5ba4bbf0f52a31544f7080caff8cc813..c95956c853600a5b205fdefb695373efe53faf6f 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "SAPI.h"
 #include "php_ini.h"
+#include "ext/standard/head.h"
 
 #include "php_http.h"
 #include "php_http_api.h"
@@ -47,6 +48,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http);
 #define HTTP_BEGIN_ARGS(method, req_args)              HTTP_BEGIN_ARGS_EX(HttpResponse, method, 0, req_args)
 #define HTTP_EMPTY_ARGS(method, ret_ref)               HTTP_EMPTY_ARGS_EX(HttpResponse, method, ret_ref)
 #define HTTP_RESPONSE_ME(method, visibility)   PHP_ME(HttpResponse, method, HTTP_ARGS(HttpResponse, method), visibility|ZEND_ACC_STATIC)
+#define HTTP_RESPONSE_ALIAS(method, func)              HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpResponse, method))
 
 HTTP_EMPTY_ARGS(getETag, 0);
 HTTP_BEGIN_ARGS(setETag, 1)
@@ -111,6 +113,26 @@ HTTP_END_ARGS;
 
 HTTP_EMPTY_ARGS(capture, 0);
 
+HTTP_BEGIN_ARGS(redirect, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(params, 0)
+       HTTP_ARG_VAL(session, 0)
+       HTTP_ARG_VAL(permanent, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(sendStatus, 1)
+       HTTP_ARG_VAL(status, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(sendHeader, 1)
+       HTTP_ARG_VAL(header, 0)
+       HTTP_ARG_VAL(replace, 0)
+       HTTP_ARG_VAL(status, 0)
+HTTP_END_ARGS;
+
+HTTP_EMPTY_ARGS(getRequestHeaders, 0);
+HTTP_EMPTY_ARGS(getRequestBody, 0);
+
 #define http_response_object_declare_default_properties() _http_response_object_declare_default_properties(TSRMLS_C)
 static inline void _http_response_object_declare_default_properties(TSRMLS_D);
 
@@ -153,6 +175,14 @@ zend_function_entry http_response_object_fe[] = {
        HTTP_RESPONSE_ME(send, ZEND_ACC_PUBLIC)
        HTTP_RESPONSE_ME(capture, ZEND_ACC_PUBLIC)
 
+       HTTP_RESPONSE_ALIAS(redirect, http_redirect)
+
+       HTTP_RESPONSE_ALIAS(sendStatus, http_send_status)
+       HTTP_RESPONSE_ALIAS(sendHeader, header)
+
+       HTTP_RESPONSE_ALIAS(getRequestHeaders, http_get_request_headers)
+       HTTP_RESPONSE_ALIAS(getRequestBody, http_get_request_body)
+
        {NULL, NULL, NULL}
 };
 
index 54baa0b106b8891f7b179016afb2b2007997cb39..b1951fbcadde6feafb15455c427cf175213fb391 100644 (file)
 #include "php_http_std_defs.h"
 #include "php_http_util_object.h"
 
-HTTP_DECLARE_ARG_PASS_INFO();
-
 zend_class_entry *http_util_object_ce;
 zend_function_entry http_util_object_fe[] = {
        HTTP_STATIC_ME_ALIAS(date, http_date, NULL)
        HTTP_STATIC_ME_ALIAS(absoluteURI, http_absolute_uri, NULL)
        HTTP_STATIC_ME_ALIAS(negotiateLanguage, http_negotiate_language, NULL)
        HTTP_STATIC_ME_ALIAS(negotiateCharset, http_negotiate_charset, NULL)
-       HTTP_STATIC_ME_ALIAS(redirect, http_redirect, NULL)
-       HTTP_STATIC_ME_ALIAS(sendStatus, http_send_status, NULL)
-       HTTP_STATIC_ME_ALIAS(sendLastModified, http_send_last_modified, NULL)
-       HTTP_STATIC_ME_ALIAS(sendContentType, http_send_content_type, NULL)
-       HTTP_STATIC_ME_ALIAS(sendContentDisposition, http_send_content_disposition, NULL)
        HTTP_STATIC_ME_ALIAS(matchModified, http_match_modified, NULL)
        HTTP_STATIC_ME_ALIAS(matchEtag, http_match_etag, NULL)
-       HTTP_STATIC_ME_ALIAS(cacheLastModified, http_cache_last_modified, NULL)
-       HTTP_STATIC_ME_ALIAS(cacheEtag, http_cache_etag, NULL)
        HTTP_STATIC_ME_ALIAS(chunkedDecode, http_chunked_decode, NULL)
        HTTP_STATIC_ME_ALIAS(splitResponse, http_split_response, NULL)
        HTTP_STATIC_ME_ALIAS(parseHeaders, http_parse_headers, NULL)
-       HTTP_STATIC_ME_ALIAS(getRequestHeaders, http_get_request_headers, NULL)
-       HTTP_STATIC_ME_ALIAS(getRequestBody, http_get_request_body, NULL)
-#ifdef HTTP_HAVE_CURL
-       HTTP_STATIC_ME_ALIAS(get, http_get, http_arg_pass_ref_3)
-       HTTP_STATIC_ME_ALIAS(head, http_head, http_arg_pass_ref_3)
-       HTTP_STATIC_ME_ALIAS(postData, http_post_data, http_arg_pass_ref_4)
-       HTTP_STATIC_ME_ALIAS(postFields, http_post_fields, http_arg_pass_ref_5)
-#endif /* HTTP_HAVE_CURL */
        HTTP_STATIC_ME_ALIAS(authBasic, http_auth_basic, NULL)
        HTTP_STATIC_ME_ALIAS(authBasicCallback, http_auth_basic_cb, NULL)
        {NULL, NULL, NULL}
index 426d0ea00b6e60fb4c0fee1cad9c31f1f9732ab9..5414fa5d70ccd2ddfd9b11ed7501dbce0ec8155a 100644 (file)
@@ -96,6 +96,18 @@ PHP_METHOD(HttpRequest, getResponseBody);
 PHP_METHOD(HttpRequest, getResponseInfo);
 PHP_METHOD(HttpRequest, getResponseMessage);
 
+PHP_METHOD(HttpRequest, get);
+PHP_METHOD(HttpRequest, head);
+PHP_METHOD(HttpRequest, postData);
+PHP_METHOD(HttpRequest, postFields);
+PHP_METHOD(HttpRequest, putFile);
+PHP_METHOD(HttpRequest, putStream);
+
+PHP_METHOD(HttpRequest, methodRegister);
+PHP_METHOD(HttpRequest, methodUnregister);
+PHP_METHOD(HttpRequest, methodName);
+PHP_METHOD(HttpRequest, methodExists);
+
 #endif
 #endif
 #endif
index 9742061b6696c940988c695f525d2a1fd1ab72dc..b114538f6de90d62a165f0371710057c92fcc3ef 100644 (file)
@@ -49,6 +49,11 @@ PHP_METHOD(HttpResponse, setStream);
 PHP_METHOD(HttpResponse, getStream);
 PHP_METHOD(HttpResponse, send);
 PHP_METHOD(HttpResponse, capture);
+PHP_METHOD(HttpResponse, redirect);
+PHP_METHOD(HttpResponse, sendStatus);
+PHP_METHOD(HttpResponse, sendHeader);
+PHP_METHOD(HttpResponse, getRequestHeaders);
+PHP_METHOD(HttpResponse, getRequestBody);
 
 #endif
 #endif
index d89c38fb535638fea104779c4e78c4d9cdee055b..8a4a9f36cc6f96bfb4964991a003af9bf1128343 100644 (file)
@@ -29,26 +29,11 @@ PHP_METHOD(HttpUtil, date);
 PHP_METHOD(HttpUtil, absoluteURI);
 PHP_METHOD(HttpUtil, negotiateLanguage);
 PHP_METHOD(HttpUtil, negotiateCharset);
-PHP_METHOD(HttpUtil, redirect);
-PHP_METHOD(HttpUtil, sendStatus);
-PHP_METHOD(HttpUtil, sendLastModified);
-PHP_METHOD(HttpUtil, sendContentType);
-PHP_METHOD(HttpUtil, sendContentDisposition);
 PHP_METHOD(HttpUtil, matchModified);
 PHP_METHOD(HttpUtil, matchEtag);
-PHP_METHOD(HttpUtil, cacheLastModified);
-PHP_METHOD(HttpUtil, cacheEtag);
 PHP_METHOD(HttpUtil, chunkedDecode);
 PHP_METHOD(HttpUtil, splitResponse);
 PHP_METHOD(HttpUtil, parseHeaders);
-PHP_METHOD(HttpUtil, getRequestHeaders);
-PHP_METHOD(HttpUtil, getRequestBody);
-#ifdef HTTP_HAVE_CURL
-PHP_METHOD(HttpUtil, get);
-PHP_METHOD(HttpUtil, head);
-PHP_METHOD(HttpUtil, postData);
-PHP_METHOD(HttpUtil, postFields);
-#endif /* HTTP_HAVE_CURL */
 PHP_METHOD(HttpUtil, authBasic);
 PHP_METHOD(HttpUtil, authBasicCallback);
 
index 6c08b8aaa64503770c3c40aec5f3f23bbb3f2072..6d8171dd639907624c89a61ab74a8613e5cb34ae 100644 (file)
@@ -1,12 +1,13 @@
 --TEST--
 HttpMessage
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 checkver(5);
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 $m = new HttpMessage(
        "HTTP/1.1 301\r\n".
        "Location: /anywhere\r\n".
@@ -26,7 +27,8 @@ var_dump($m->toString());
 var_dump(HttpMessage::fromString($m->toString())->toString());
 ?>
 --EXPECTF--
-%sstring(1) "X"
+%sTEST
+string(1) "X"
 string(134) "HTTP/1.1 301
 Location: /anywhere
 HTTP/1.1 302
@@ -47,3 +49,4 @@ Content-Length: 1
 
 X
 "
+
index 3f5f2edfc7090814a05eb3104de96d00a87e22da..ec28bdfbe8f4b516bb1c2ba0ee8a70fb5642ffb8 100644 (file)
@@ -1,12 +1,13 @@
 --TEST--
 HttpRequest options
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 checkver(5);
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 $r1 = new HttpRequest;
 $r2 = new HttpRequest;
 $r1->setOptions(array('redirect'=>11, 'headers'=>array('X-Foo'=>'Bar')));
@@ -21,7 +22,8 @@ $r1 = null;
 $r2 = null;
 ?>
 --EXPECTF--
-%sArray
+%sTEST
+Array
 (
     [0] => Array
         (
@@ -46,4 +48,4 @@ $r2 = null;
         )
 
 )
-bool(false)
\ No newline at end of file
+bool(false)
index 0c20be0150f8f8314c0c87117f5fc2f0848492c8..e76191e9ff2d71638d02406b363f74938a046197 100644 (file)
@@ -1,14 +1,17 @@
 --TEST--
 http_absolute_uri() with relative paths
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 echo http_absolute_uri('page'), "\n";
 echo http_absolute_uri('with/some/path/'), "\n";
 ?>
 --EXPECTF--
-%shttp://localhost/page
+%sTEST
+http://localhost/page
 http://localhost/with/some/path/
+
index cccae322d8f2b757d297e21711bd05ec24d471f5..47f796b486672d634caa96403cf053b1f4d0ff25 100644 (file)
@@ -1,16 +1,19 @@
 --TEST--
 http_absolute_uri() with proto
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 echo http_absolute_uri('sec', 'https'), "\n";
 echo http_absolute_uri('/pub', 'ftp'), "\n";
 echo http_absolute_uri('/', null), "\n";
 ?>
 --EXPECTF--
-%shttps://localhost/sec
+%sTEST
+https://localhost/sec
 ftp://localhost/pub
 http://localhost/
+
index dd53ea4a27ed0c7702d8249336561dfb48968f41..27f750b1bfecc6e9ad96af0c305fc91953412889 100644 (file)
@@ -1,12 +1,13 @@
 --TEST--
 http_chunked_decode()
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 ?>
 --FILE--
 <?php
-$data = 
+echo "-TEST\n";
+$data =
 "02\r\n".
 "ab\r\n".
 "03\r\n".
@@ -18,8 +19,7 @@ $data =
 var_dump(http_chunked_decode($data));
 ?>
 --EXPECTF--
-Content-type: text/html
-X-Powered-By: PHP/%s
-
+%sTEST
 string(9) "aba
 cabcd"
+
index c50375665faabb448f0f90134c7a7cf75dbc125b..7964be715cea6f92153903b7eaec10698e08b1b1 100644 (file)
@@ -1,14 +1,17 @@
 --TEST--
 http_date() with timestamp
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 echo http_date(1), "\n";
 echo http_date(1234567890), "\n";
 ?>
 --EXPECTF--
-%sThu, 01 Jan 1970 00:00:01 GMT
+%sTEST
+Thu, 01 Jan 1970 00:00:01 GMT
 Fri, 13 Feb 2009 23:31:30 GMT
+
index 9fdb15e84db963cbe91d38298a5a0e53cc5797cb..98ab785b0b7148b0d53ffcea2bcbd2c7875604cd 100644 (file)
@@ -1,11 +1,12 @@
 --TEST--
 http_date() without timestamp
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 $t = time();
 $d1 = http_date($t);
 $d2 = http_date($t);
@@ -13,7 +14,9 @@ var_dump($d1 === $d2);
 echo strtotime($d1), "\n$d1\n$d2\n";
 ?>
 --EXPECTF--
-%sbool(true)
+%sTEST
+bool(true)
 %d
 %s, %d %s %d %d:%d:%d GMT
 %s, %d %s %d %d:%d:%d GMT
+
index cbb742b57b0790343c44fc9b704472118a4f5ba8..1e095f2dd1d933959f24fd67e47162766c842b5e 100644 (file)
@@ -1,11 +1,12 @@
 --TEST--
 http_parse_headers()
 --SKIPIF--
-<?php 
+<?php
 include 'skip.inc';
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 print_r(http_parse_headers(
 "Host: localhost\r\n".
 "Host: ambigious\r\n".
@@ -22,7 +23,8 @@ print_r(http_parse_headers(
 ));
 ?>
 --EXPECTF--
-%sArray
+%sTEST
+Array
 (
     [Host] => Array
         (
@@ -37,4 +39,5 @@ print_r(http_parse_headers(
     [Folded] => one
        two
   three
-)
\ No newline at end of file
+)
+
index 6c7bc5e021c4eda10a8c8b9d8846a4f143e444e7..f3d73a5e7aab8408adeb1e621f01746019f3b2c7 100644 (file)
@@ -6,12 +6,14 @@ include 'skip.inc';
 ?>
 --FILE--
 <?php
+echo "-TEST\n";
 $data = "HTTP/1.1 200 Ok\r\nContent-Type: text/plain\r\nContent-Language: de-AT\r\nDate: Sat, 22 Jan 2005 18:10:02 GMT\r\n\r\nHallo Du!";
 var_export(http_split_response($data));
 echo "\nDone\n";
 ?>
 --EXPECTF--
-%sarray (
+%sTEST
+array (
   0 => 
   array (
     'Response Status' => '200 Ok',