remove 90% of the request method cruft; request methods are now simple strings
authorMichael Wallner <mike@php.net>
Thu, 22 Mar 2012 16:21:26 +0000 (16:21 +0000)
committerMichael Wallner <mike@php.net>
Thu, 22 Mar 2012 16:21:26 +0000 (16:21 +0000)
12 files changed:
package.xml
php_http.c
php_http_curl.c
php_http_request.c
php_http_request.h
php_http_request_factory.c
php_http_request_method.c
php_http_request_method.h
php_http_request_pool.c
php_http_request_pool.h
phpunit/RequestTest.php
tests/requestpool001.phpt

index bc6add8ed4a391bc23326589714c99f515c4fdc5..3f34a5998c87d70c8a67a19e3936de4cdbabc2b4 100644 (file)
@@ -41,6 +41,7 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be
 - Renamed http\Env\Request::getPost() to ::getForm()
 - Changed http\Env\Response::setContentDisposition() to take an http\Params like array as argument
 - Removed http\Env\Response::CONTENT_DISPOSOTION_* constants
+- Removed http\Env\Request\Method class; request methods are now used as simple strings
 ]]></notes>
  <contents>
   <dir name="/">
index d5211bcee1cefad5d718674ebf1dcd0d3fd48d1f..202317c8fc9a3417ef38acee98049daabf3dac39 100644 (file)
@@ -146,7 +146,6 @@ PHP_MINIT_FUNCTION(http)
        || SUCCESS != PHP_MINIT_CALL(http_curl)
 #endif
        || SUCCESS != PHP_MINIT_CALL(http_request_datashare)
-       || SUCCESS != PHP_MINIT_CALL(http_request_method)
        || SUCCESS != PHP_MINIT_CALL(http_request_pool)
        || SUCCESS != PHP_MINIT_CALL(http_url)
        || SUCCESS != PHP_MINIT_CALL(http_env)
index 65b1746b8f7b38ac7a71f71c584d49fe108c3b44..9bfeda8d81dc3b0c67a346c0f6e55a5135ae4725 100644 (file)
@@ -239,6 +239,8 @@ static int php_http_curl_raw_callback(CURL *ch, curl_infotype type, char *data,
                                curl->progress.state.info = "not disconnected";
                        } else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) {
                                curl->progress.state.info = "disconnected";
+                       } else if (php_memnstr(data, ZEND_STRL("Issue another request"), data + length)) {
+                               curl->progress.state.info = "redirect";
                        }
                        php_http_request_progress_notify(&curl->progress TSRMLS_CC);
                        break;
@@ -288,7 +290,7 @@ static int php_http_curl_dummy_callback(char *data, size_t n, size_t l, void *s)
        return n*l;
 }
 
-static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body)
+static STATUS php_http_curl_request_prepare(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body)
 {
        php_http_curl_request_t *curl = h->ctx;
        php_http_curl_request_storage_t *storage = get_storage(curl->handle);
@@ -302,30 +304,28 @@ static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_requ
        curl_easy_setopt(curl->handle, CURLOPT_URL, storage->url);
 
        /* request method */
-       switch (meth) {
-               case PHP_HTTP_GET:
+       switch (php_http_request_method_is(meth, 4, "GET", "HEAD", "POST", "PUT")) {
+               case 0:
                        curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L);
                        break;
 
-               case PHP_HTTP_HEAD:
+               case 1:
                        curl_easy_setopt(curl->handle, CURLOPT_NOBODY, 1L);
                        break;
 
-               case PHP_HTTP_POST:
+               case 2:
                        curl_easy_setopt(curl->handle, CURLOPT_POST, 1L);
                        break;
 
-               case PHP_HTTP_PUT:
+               case 3:
                        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L);
                        break;
 
                default: {
-                       const char *name = php_http_request_method_name(meth TSRMLS_CC);
-
-                       if (name) {
-                               curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, name);
+                       if (meth) {
+                               curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, meth);
                        } else {
-                               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", meth, url);
+                               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: '%s' (%s)", meth, url);
                                return FAILURE;
                        }
                        break;
@@ -340,17 +340,12 @@ static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_requ
                 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
                 * does not allow a request body.
                 */
-               switch (meth) {
-                       default: {
-                               size_t body_size = php_http_message_body_size(body);
-
-                               curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, body);
-                               curl_easy_setopt(curl->handle, CURLOPT_READDATA, body);
-                               curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
-                               curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
-                               break;
-                       }
-               }
+               size_t body_size = php_http_message_body_size(body);
+
+               curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, body);
+               curl_easy_setopt(curl->handle, CURLOPT_READDATA, body);
+               curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
+               curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
        }
 
        return SUCCESS;
@@ -1290,7 +1285,7 @@ static void php_http_curl_request_pool_dtor(php_http_request_pool_t *h)
        h->ctx = NULL;
 }
 
-static STATUS php_http_curl_request_pool_attach(php_http_request_pool_t *h, php_http_request_t *r, php_http_request_method_t m, const char *url, php_http_message_body_t *body)
+static STATUS php_http_curl_request_pool_attach(php_http_request_pool_t *h, php_http_request_t *r, const char *m, const char *url, php_http_message_body_t *body)
 {
        php_http_curl_request_pool_t *curl = h->ctx;
        php_http_curl_request_t *recurl = r->ctx;
@@ -1705,7 +1700,7 @@ static STATUS php_http_curl_request_reset(php_http_request_t *h)
        return SUCCESS;
 }
 
-static STATUS php_http_curl_request_exec(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body)
+static STATUS php_http_curl_request_exec(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body)
 {
        uint tries = 0;
        CURLcode result;
index 42416890aaa6239e372b764a75fa8b17b9845493..a7086d370eedd683db1dec74085a534e6cecc182 100644 (file)
@@ -94,7 +94,7 @@ PHP_HTTP_API php_http_request_t *php_http_request_copy(php_http_request_t *from,
        }
 }
 
-PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body)
+PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body)
 {
        if (h->ops->exec) {
                return h->ops->exec(h, meth, url, body);
@@ -416,7 +416,7 @@ static inline zend_object_value php_http_request_object_message(zval *this_ptr,
        }
 }
 
-STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, php_http_request_method_t *meth, char **url, php_http_message_body_t **body TSRMLS_DC)
+STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC)
 {
        zval *zoptions;
        php_http_request_progress_t *progress;
@@ -427,7 +427,7 @@ STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zv
        zend_update_property_null(php_http_request_class_entry, getThis(), ZEND_STRL("info") TSRMLS_CC);
 
        if (meth) {
-               *meth = (php_http_request_method_t) Z_LVAL_P(zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("method"), 0 TSRMLS_CC));
+               *meth = Z_STRVAL_P(zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("method"), 0 TSRMLS_CC));
        }
 
        if (url) {
@@ -948,10 +948,11 @@ PHP_METHOD(HttpRequest, getUrl)
 
 PHP_METHOD(HttpRequest, setMethod)
 {
-       long meth;
+       char *meth_str;
+       int meth_len;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) {
-               zend_update_property_long(php_http_request_class_entry, getThis(), ZEND_STRL("method"), meth TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) {
+               zend_update_property_stringl(php_http_request_class_entry, getThis(), ZEND_STRL("method"), meth_str, meth_len TSRMLS_CC);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
 }
@@ -1291,8 +1292,8 @@ PHP_METHOD(HttpRequest, send)
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                if (SUCCESS == zend_parse_parameters_none()) {
                        php_http_request_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-                       php_http_request_method_t meth = PHP_HTTP_NO_REQUEST_METHOD;
                        php_http_message_body_t *body = NULL;
+                       char *meth = NULL;
                        char *url = NULL;
 
                        if (SUCCESS == php_http_request_object_requesthandler(obj, getThis(), &meth, &url, &body TSRMLS_CC)) {
@@ -1327,7 +1328,7 @@ PHP_MINIT_FUNCTION(http_request)
        zend_declare_property_long(php_http_request_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_null(php_http_request_class_entry, ZEND_STRL("requestMessage"), ZEND_ACC_PRIVATE TSRMLS_CC);
-       zend_declare_property_long(php_http_request_class_entry, ZEND_STRL("method"), PHP_HTTP_GET, ZEND_ACC_PRIVATE TSRMLS_CC);
+       zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("method"), "GET", ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("url"), "", ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("contentType"), "", ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_string(php_http_request_class_entry, ZEND_STRL("requestBody"), "", ZEND_ACC_PRIVATE TSRMLS_CC);
index 3d7b78c1005c8e1e7ea42cdd48afdace9a29afc5..99f75d9c531fbc95750ef47396125b2ab2fcbef7 100644 (file)
@@ -125,7 +125,7 @@ typedef struct php_http_request php_http_request_t;
 typedef php_http_request_t *(*php_http_request_init_func_t)(php_http_request_t *h, void *arg);
 typedef php_http_request_t *(*php_http_request_copy_func_t)(php_http_request_t *from, php_http_request_t *to);
 typedef void (*php_http_request_dtor_func_t)(php_http_request_t *h);
-typedef STATUS (*php_http_request_exec_func_t)(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body);
+typedef STATUS (*php_http_request_exec_func_t)(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body);
 typedef STATUS (*php_http_request_reset_func_t)(php_http_request_t *h);
 typedef STATUS (*php_http_request_setopt_func_t)(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg);
 typedef STATUS (*php_http_request_getopt_func_t)(php_http_request_t *h, php_http_request_getopt_opt_t opt, void *arg);
@@ -157,7 +157,7 @@ struct php_http_request {
 
 PHP_HTTP_API php_http_request_t *php_http_request_init(php_http_request_t *h, php_http_request_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC);
 PHP_HTTP_API php_http_request_t *php_http_request_copy(php_http_request_t *from, php_http_request_t *to);
-PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body);
+PHP_HTTP_API STATUS php_http_request_exec(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body);
 PHP_HTTP_API STATUS php_http_request_reset(php_http_request_t *h);
 PHP_HTTP_API STATUS php_http_request_setopt(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg);
 PHP_HTTP_API STATUS php_http_request_getopt(php_http_request_t *h, php_http_request_getopt_opt_t opt, void *arg);
@@ -177,7 +177,7 @@ extern zend_object_value php_http_request_object_new_ex(zend_class_entry *ce, ph
 extern zend_object_value php_http_request_object_clone(zval *zobject TSRMLS_DC);
 extern void php_http_request_object_free(void *object TSRMLS_DC);
 
-extern STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, php_http_request_method_t *meth, char **url, php_http_message_body_t **body TSRMLS_DC);
+extern STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC);
 extern STATUS php_http_request_object_responsehandler(php_http_request_object_t *obj, zval *this_ptr TSRMLS_DC);
 
 PHP_METHOD(HttpRequest, __construct);
index 79e348f15a95b5f1ec15d6945b92b5455062e650..e739f53701ef0e345177c526adc873c29dfa3138 100644 (file)
@@ -113,13 +113,12 @@ PHP_METHOD(HttpRequestFactory, __construct)
 
 PHP_METHOD(HttpRequestFactory, createRequest)
 {
-       char *url_str = NULL;
-       int url_len;
-       long meth = -1;
+       char *meth_str = NULL, *url_str = NULL;
+       int meth_len, url_len;
        zval *options = NULL;
 
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!la!", &url_str, &url_len, &meth, &options)) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!a!", &url_str, &url_len, &meth_str, &meth_len, &options)) {
                        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                                zval *zdriver, *os;
                                zend_object_value ov;
@@ -166,8 +165,8 @@ PHP_METHOD(HttpRequestFactory, createRequest)
                                                        if (url_str) {
                                                                zend_update_property_stringl(php_http_request_class_entry, return_value, ZEND_STRL("url"), url_str, url_len TSRMLS_CC);
                                                        }
-                                                       if (meth > 0) {
-                                                               zend_update_property_long(php_http_request_class_entry, return_value, ZEND_STRL("method"), meth TSRMLS_CC);
+                                                       if (meth_str) {
+                                                               zend_update_property_stringl(php_http_request_class_entry, return_value, ZEND_STRL("method"), meth_str, meth_len TSRMLS_CC);
                                                        }
                                                        if (options) {
                                                                zend_call_method_with_1_params(&return_value, Z_OBJCE_P(return_value), NULL, "setoptions", NULL, options);
index 118721f550ce5e55858f07aefa4817c4c5a157e0..13561adba1dc89e26db795fd838d32a98100724d 100644 (file)
 
 #include "php_http_api.h"
 
-static PHP_HTTP_STRLIST(php_http_request_methods) =
-       PHP_HTTP_STRLIST_ITEM("UNKNOWN")
-       /* HTTP/1.1 */
-       PHP_HTTP_STRLIST_ITEM("GET")
-       PHP_HTTP_STRLIST_ITEM("HEAD")
-       PHP_HTTP_STRLIST_ITEM("POST")
-       PHP_HTTP_STRLIST_ITEM("PUT")
-       PHP_HTTP_STRLIST_ITEM("DELETE")
-       PHP_HTTP_STRLIST_ITEM("OPTIONS")
-       PHP_HTTP_STRLIST_ITEM("TRACE")
-       PHP_HTTP_STRLIST_ITEM("CONNECT")
-       /* WebDAV - RFC 2518 */
-       PHP_HTTP_STRLIST_ITEM("PROPFIND")
-       PHP_HTTP_STRLIST_ITEM("PROPPATCH")
-       PHP_HTTP_STRLIST_ITEM("MKCOL")
-       PHP_HTTP_STRLIST_ITEM("COPY")
-       PHP_HTTP_STRLIST_ITEM("MOVE")
-       PHP_HTTP_STRLIST_ITEM("LOCK")
-       PHP_HTTP_STRLIST_ITEM("UNLOCK")
-       /* WebDAV Versioning - RFC 3253 */
-       PHP_HTTP_STRLIST_ITEM("VERSION_CONTROL")
-       PHP_HTTP_STRLIST_ITEM("REPORT")
-       PHP_HTTP_STRLIST_ITEM("CHECKOUT")
-       PHP_HTTP_STRLIST_ITEM("CHECKIN")
-       PHP_HTTP_STRLIST_ITEM("UNCHECKOUT")
-       PHP_HTTP_STRLIST_ITEM("MKWORKSPACE")
-       PHP_HTTP_STRLIST_ITEM("UPDATE")
-       PHP_HTTP_STRLIST_ITEM("LABEL")
-       PHP_HTTP_STRLIST_ITEM("MERGE")
-       PHP_HTTP_STRLIST_ITEM("BASELINE_CONTROL")
-       PHP_HTTP_STRLIST_ITEM("MKACTIVITY")
-       /* WebDAV Access Control - RFC 3744 */
-       PHP_HTTP_STRLIST_ITEM("ACL")
-       PHP_HTTP_STRLIST_STOP
-;
-
-PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth TSRMLS_DC)
-{
-       if (meth > PHP_HTTP_NO_REQUEST_METHOD && meth < PHP_HTTP_MAX_REQUEST_METHOD) {
-               return php_http_strlist_find(php_http_request_methods, 0, meth);
-       } else {
-               zval **val, *cmp, res;
-               HashPosition pos;
-               php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
-
-               INIT_PZVAL(&res);
-               FOREACH_HASH_KEYVAL(pos, &php_http_request_class_entry->constants_table, key, val) {
-                       MAKE_STD_ZVAL(cmp);
-                       ZVAL_LONG(cmp, meth);
-                       is_equal_function(&res, *val, cmp TSRMLS_CC);
-                       zval_ptr_dtor(&cmp);
-
-                       if (Z_LVAL(res)) {
-                               return key.str;
-                       }
-               }
-       }
-       return NULL;
-}
-
-PHP_HTTP_API STATUS php_http_request_method_register(const char *meth_str, size_t meth_len, long *id TSRMLS_DC)
-{
-       long num = zend_hash_num_elements(&php_http_request_class_entry->constants_table);
-
-       if (SUCCESS == zend_declare_class_constant_long(php_http_request_method_class_entry, meth_str, meth_len, num TSRMLS_CC)) {
-               if (id) {
-                       *id = num;
-               }
-               return SUCCESS;
-       }
-       return FAILURE;
-}
-
-zend_class_entry *php_http_request_method_class_entry;
-
-#define PHP_HTTP_BEGIN_ARGS(method, req_args)  PHP_HTTP_BEGIN_ARGS_EX(HttpRequestMethod, method, 0, req_args)
-#define PHP_HTTP_EMPTY_ARGS(method)                            PHP_HTTP_EMPTY_ARGS_EX(HttpRequestMethod, method, 0)
-#define PHP_HTTP_REQMETH_ME(method, visibility)        PHP_ME(HttpRequestMethod, method, PHP_HTTP_ARGS(HttpRequestMethod, method), visibility)
-
-#ifdef register
-#      undef register
-#endif
-
-PHP_HTTP_BEGIN_ARGS(__construct, 1)
-       PHP_HTTP_ARG_VAL(name, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(__toString);
-
-PHP_HTTP_EMPTY_ARGS(getId);
-
-PHP_HTTP_BEGIN_ARGS(exists, 1)
-       PHP_HTTP_ARG_VAL(method, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(register, 1)
-       PHP_HTTP_ARG_VAL(method, 0)
-PHP_HTTP_END_ARGS;
-
-zend_function_entry php_http_request_method_method_entry[] = {
-       PHP_HTTP_REQMETH_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
-       PHP_HTTP_REQMETH_ME(__toString, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQMETH_ME(getId, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQMETH_ME(exists, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
-       PHP_HTTP_REQMETH_ME(register, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
-
-       EMPTY_FUNCTION_ENTRY
-};
-
-PHP_METHOD(HttpRequestMethod, __construct)
+PHP_HTTP_API int php_http_request_method_is(const char *meth, int argc, ...)
 {
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
-               char *meth_str;
-               int meth_len;
+       va_list argv;
+       int match = -1;
 
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
-                               zval *zarg, *zret;
+       if (argc > 0) {
+               int i;
 
-                               if (SUCCESS == zend_get_parameters(ZEND_NUM_ARGS(), 1, &zarg)) {
-                                       if (zend_call_method_with_1_params(&getThis(), php_http_request_method_class_entry, NULL, "exists", &zret, zarg)) {
-                                               if (i_zend_is_true(zret)) {
-                                                       zend_update_property_stringl(php_http_request_method_class_entry, getThis(), ZEND_STRL("name"), meth_str, meth_len TSRMLS_CC);
-                                               } else {
-                                                       php_http_error(HE_THROW, PHP_HTTP_E_REQUEST_METHOD, "Unknown request method '%s'", meth_str);
-                                               }
-                                               zval_ptr_dtor(&zret);
-                                       }
-                               }
-                       } end_error_handling();
-               }
-       } end_error_handling();
-}
+               va_start(argv, argc);
+               for (i = 0; i < argc; ++i) {
+                       const char *test = va_arg(argv, const char *);
 
-PHP_METHOD(HttpRequestMethod, __toString)
-{
-       if (SUCCESS == zend_parse_parameters_none()) {
-               zval *retval = php_http_ztyp(IS_STRING, zend_read_property(php_http_request_method_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
-
-               RETURN_ZVAL(retval, 1, 1);
-       }
-       RETURN_EMPTY_STRING();
-}
-
-PHP_METHOD(HttpRequestMethod, getId)
-{
-       if (SUCCESS == zend_parse_parameters_none()) {
-               zval **data, *meth = php_http_ztyp(IS_STRING, zend_read_property(php_http_request_method_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
-
-               if (SUCCESS == zend_hash_find(&php_http_request_method_class_entry->constants_table, Z_STRVAL_P(meth), Z_STRLEN_P(meth) + 1, (void *) &data)) {
-                       zval_ptr_dtor(&meth);
-                       RETURN_ZVAL(*data, 1, 0);
+                       if (!strcasecmp(meth, test)) {
+                               match = i;
+                               break;
+                       }
                }
-               zval_ptr_dtor(&meth);
+               va_end(argv);
        }
-       RETURN_FALSE;
-}
-
-PHP_METHOD(HttpRequestMethod, exists)
-{
-       char *meth_str;
-       int meth_len;
-
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) {
-               zval **data;
 
-               if (SUCCESS == zend_hash_find(&php_http_request_method_class_entry->constants_table, meth_str, meth_len + 1, (void *) &data)) {
-                       RETURN_ZVAL(*data, 1, 0);
-               }
-       }
-       RETURN_FALSE;
+       return match;
 }
 
-PHP_METHOD(HttpRequestMethod, register)
-{
-       char *meth_str;
-       int meth_len;
-
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &meth_str, &meth_len)) {
-               RETURN_SUCCESS(zend_declare_class_constant_long(php_http_request_method_class_entry, meth_str, meth_len, zend_hash_num_elements(&php_http_request_method_class_entry->constants_table) TSRMLS_CC));
-       }
-       RETURN_FALSE;
-}
-
-PHP_MINIT_FUNCTION(http_request_method)
-{
-       php_http_strlist_iterator_t std;
-
-       PHP_HTTP_REGISTER_CLASS(http\\Request, Method, http_request_method, php_http_object_class_entry, 0);
-
-       zend_declare_property_null(php_http_request_method_class_entry, ZEND_STRL("name"), ZEND_ACC_PROTECTED TSRMLS_CC);
-
-       php_http_strlist_iterator_init(&std, php_http_request_methods, 1);
-       do {
-               unsigned id;
-               const char *meth = php_http_strlist_iterator_this(&std, &id);
-
-               zend_declare_class_constant_long(php_http_request_method_class_entry, meth, strlen(meth), id TSRMLS_CC);
-       } while (*php_http_strlist_iterator_next(&std));
-
-       return SUCCESS;
-}
-
-
 /*
  * Local variables:
  * tab-width: 4
index dcfd9b894423a4826d61efa7f0afb4f016d5659a..85eedbd96b1b5d155c8ae835e5feab77126dddb6 100644 (file)
 #ifndef PHP_HTTP_REQUEST_METHOD_H
 #define PHP_HTTP_REQUEST_METHOD_H
 
-typedef enum php_http_request_method {
-       /* force the enum to be signed */
-       PHP_HTTP_NEG_REQUEST_METHOD     =-1,
-       PHP_HTTP_NO_REQUEST_METHOD      = 0,
-       /* HTTP/1.1 */
-       PHP_HTTP_GET                            = 1,
-       PHP_HTTP_HEAD                           = 2,
-       PHP_HTTP_POST                           = 3,
-       PHP_HTTP_PUT                            = 4,
-       PHP_HTTP_DELETE                         = 5,
-       PHP_HTTP_OPTIONS                        = 6,
-       PHP_HTTP_TRACE                          = 7,
-       PHP_HTTP_CONNECT                        = 8,
-       /* WebDAV - RFC 2518 */
-       PHP_HTTP_PROPFIND                       = 9,
-       PHP_HTTP_PROPPATCH                      = 10,
-       PHP_HTTP_MKCOL                          = 11,
-       PHP_HTTP_COPY                           = 12,
-       PHP_HTTP_MOVE                           = 13,
-       PHP_HTTP_LOCK                           = 14,
-       PHP_HTTP_UNLOCK                         = 15,
-       /* WebDAV Versioning - RFC 3253 */
-       PHP_HTTP_VERSION_CONTROL        = 16,
-       PHP_HTTP_REPORT                         = 17,
-       PHP_HTTP_CHECKOUT                       = 18,
-       PHP_HTTP_CHECKIN                        = 19,
-       PHP_HTTP_UNCHECKOUT                     = 20,
-       PHP_HTTP_MKWORKSPACE            = 21,
-       PHP_HTTP_UPDATE                         = 22,
-       PHP_HTTP_LABEL                          = 23,
-       PHP_HTTP_MERGE                          = 24,
-       PHP_HTTP_BASELINE_CONTROL       = 25,
-       PHP_HTTP_MKACTIVITY                     = 26,
-       /* WebDAV Access Control - RFC 3744 */
-       PHP_HTTP_ACL                            = 27,
-       PHP_HTTP_MAX_REQUEST_METHOD     = 28
-} php_http_request_method_t;
-
-PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth TSRMLS_DC);
-PHP_HTTP_API STATUS php_http_request_method_register(const char *meth_str, size_t meth_len, long *id TSRMLS_DC);
-
-extern zend_class_entry *php_http_request_method_class_entry;
-extern zend_function_entry php_http_request_method_method_entry[];
-
-extern PHP_METHOD(HttpRequestMethod, __construct);
-extern PHP_METHOD(HttpRequestMethod, __toString);
-extern PHP_METHOD(HttpRequestMethod, getId);
-
-extern PHP_METHOD(HttpRequestMethod, exists);
-extern PHP_METHOD(HttpRequestMethod, register);
-
-extern PHP_MINIT_FUNCTION(http_request_method);
+PHP_HTTP_API int php_http_request_method_is(const char *meth, int argc, ...);
 
 #endif
 
index de7950486f8237a1ca9bea335d5b84bde60b99eb..352c8effa9171618dd48283a7962d87df5afc8c7 100644 (file)
@@ -74,7 +74,7 @@ PHP_HTTP_API STATUS php_http_request_pool_attach(php_http_request_pool_t *h, zva
 
        if (h->ops->attach) {
                char *url = NULL;
-               php_http_request_method_t m = PHP_HTTP_NO_REQUEST_METHOD;
+               char *m = NULL;
                php_http_message_body_t *body = NULL;
                php_http_request_object_t *obj = zend_object_store_get_object(request TSRMLS_CC);
 
index d5657a60d0b8c29ea5a5c77dcc633aca3df15f70..c0903302f497425152c080af3125cc8a2060e695 100644 (file)
@@ -27,7 +27,7 @@ typedef void (*php_http_request_pool_reset_func_t)(php_http_request_pool_t *p);
 typedef STATUS (*php_http_request_pool_exec_func_t)(php_http_request_pool_t *p);
 typedef STATUS (*php_http_request_pool_wait_func_t)(php_http_request_pool_t *p, struct timeval *custom_timeout);
 typedef int (*php_http_request_pool_once_func_t)(php_http_request_pool_t *p);
-typedef STATUS (*php_http_request_pool_attach_func_t)(php_http_request_pool_t *p, php_http_request_t *r, php_http_request_method_t m, const char *url, php_http_message_body_t *body);
+typedef STATUS (*php_http_request_pool_attach_func_t)(php_http_request_pool_t *p, php_http_request_t *r, const char *m, const char *url, php_http_message_body_t *body);
 typedef STATUS (*php_http_request_pool_detach_func_t)(php_http_request_pool_t *p, php_http_request_t *r);
 typedef STATUS (*php_http_request_pool_setopt_func_t)(php_http_request_pool_t *p, php_http_request_pool_setopt_opt_t opt, void *arg);
 
index 1126328e8b7f33bb7cf960e58c98160da4b539f8..fccad01edfec3b93feda3119c8f5c9f6ff9e08c8 100644 (file)
@@ -102,7 +102,7 @@ class RequestTest extends PHPUnit_Framework_TestCase
 
         $this->r->recordHistory = true;
 
-        $this->r->setMethod(http\Request\Method::POST);
+        $this->r->setMethod("POST");
         $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php");
 
         $this->r->send();
index 462af710759852cb0e42ea905719625795847711..790823c7310fac3d4f1715079a44653976b1489c 100644 (file)
@@ -9,7 +9,6 @@ include 'skipif.inc';
 
 use http\request\Factory as HttpRequestFactory;
 use http\request\Pool as HttpRequestPool;
-use http\request\Method as HttpRequestMethod;
 use http\Exception as HttpRequestException;
 use http\Exception as HttpSocketException;
 
@@ -53,7 +52,7 @@ class Pool extends HttpRequestPool
                        $this->attach(
                                $this->factory->createRequest(
                                        $url,
-                                       HttpRequestMethod::GET,
+                                       "GET",
                                        array(
                                                'redirect'      => 5,
                                                'compress'  => GZIP,
@@ -105,7 +104,7 @@ class Pool extends HttpRequestPool
                                $this->attach(
                                        $this->factory->createRequest(
                                                $url,
-                                               HttpRequestMethod::GET,
+                                               "GET",
                                                array(
                                                        'redirect'      => 5,
                                                        'compress'      => GZIP,