From: Michael Wallner Date: Sun, 24 Jul 2005 08:51:41 +0000 (+0000) Subject: - API juggling X-Git-Tag: RELEASE_0_10_0~10 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6deee2e3d2d6282dd76e3725fe2de6c7833bd57f;p=m6w6%2Fext-http - API juggling - make tests -which can- working with CLI and CGI --- diff --git a/http_request_object.c b/http_request_object.c index 4fcddab..4d86227 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -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; diff --git a/http_response_object.c b/http_response_object.c index f7cb216..c95956c 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -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} }; diff --git a/http_util_object.c b/http_util_object.c index 54baa0b..b1951fb 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -27,34 +27,17 @@ #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} diff --git a/php_http_request_object.h b/php_http_request_object.h index 426d0ea..5414fa5 100644 --- a/php_http_request_object.h +++ b/php_http_request_object.h @@ -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 diff --git a/php_http_response_object.h b/php_http_response_object.h index 9742061..b114538 100644 --- a/php_http_response_object.h +++ b/php_http_response_object.h @@ -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 diff --git a/php_http_util_object.h b/php_http_util_object.h index d89c38f..8a4a9f3 100644 --- a/php_http_util_object.h +++ b/php_http_util_object.h @@ -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); diff --git a/tests/HttpMessage_001.phpt b/tests/HttpMessage_001.phpt index 6c08b8a..6d8171d 100644 --- a/tests/HttpMessage_001.phpt +++ b/tests/HttpMessage_001.phpt @@ -1,12 +1,13 @@ --TEST-- HttpMessage --SKIPIF-- - --FILE-- 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 " + diff --git a/tests/HttpRequest_001.phpt b/tests/HttpRequest_001.phpt index 3f5f2ed..ec28bdf 100644 --- a/tests/HttpRequest_001.phpt +++ b/tests/HttpRequest_001.phpt @@ -1,12 +1,13 @@ --TEST-- HttpRequest options --SKIPIF-- - --FILE-- 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) diff --git a/tests/abs_uri_001.phpt b/tests/abs_uri_001.phpt index 0c20be0..e76191e 100644 --- a/tests/abs_uri_001.phpt +++ b/tests/abs_uri_001.phpt @@ -1,14 +1,17 @@ --TEST-- http_absolute_uri() with relative paths --SKIPIF-- - --FILE-- --EXPECTF-- -%shttp://localhost/page +%sTEST +http://localhost/page http://localhost/with/some/path/ + diff --git a/tests/abs_uri_002.phpt b/tests/abs_uri_002.phpt index cccae32..47f796b 100644 --- a/tests/abs_uri_002.phpt +++ b/tests/abs_uri_002.phpt @@ -1,16 +1,19 @@ --TEST-- http_absolute_uri() with proto --SKIPIF-- - --FILE-- --EXPECTF-- -%shttps://localhost/sec +%sTEST +https://localhost/sec ftp://localhost/pub http://localhost/ + diff --git a/tests/chunked_decode_001.phpt b/tests/chunked_decode_001.phpt index dd53ea4..27f750b 100644 --- a/tests/chunked_decode_001.phpt +++ b/tests/chunked_decode_001.phpt @@ -1,12 +1,13 @@ --TEST-- http_chunked_decode() --SKIPIF-- - --FILE-- --EXPECTF-- -Content-type: text/html -X-Powered-By: PHP/%s - +%sTEST string(9) "aba cabcd" + diff --git a/tests/date_001.phpt b/tests/date_001.phpt index c503756..7964be7 100644 --- a/tests/date_001.phpt +++ b/tests/date_001.phpt @@ -1,14 +1,17 @@ --TEST-- http_date() with timestamp --SKIPIF-- - --FILE-- --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 + diff --git a/tests/date_002.phpt b/tests/date_002.phpt index 9fdb15e..98ab785 100644 --- a/tests/date_002.phpt +++ b/tests/date_002.phpt @@ -1,11 +1,12 @@ --TEST-- http_date() without timestamp --SKIPIF-- - --FILE-- --EXPECTF-- -%sbool(true) +%sTEST +bool(true) %d %s, %d %s %d %d:%d:%d GMT %s, %d %s %d %d:%d:%d GMT + diff --git a/tests/parse_headers_001.phpt b/tests/parse_headers_001.phpt index cbb742b..1e095f2 100644 --- a/tests/parse_headers_001.phpt +++ b/tests/parse_headers_001.phpt @@ -1,11 +1,12 @@ --TEST-- http_parse_headers() --SKIPIF-- - --FILE-- --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 +) + diff --git a/tests/split_response_001.phpt b/tests/split_response_001.phpt index 6c7bc5e..f3d73a5 100644 --- a/tests/split_response_001.phpt +++ b/tests/split_response_001.phpt @@ -6,12 +6,14 @@ include 'skip.inc'; ?> --FILE-- --EXPECTF-- -%sarray ( +%sTEST +array ( 0 => array ( 'Response Status' => '200 Ok',