From: Michael Wallner Date: Thu, 17 Mar 2005 14:45:41 +0000 (+0000) Subject: * added HTTPi_Request::unsetOptions(), HTTPi_Request::addHeader(), HTTPi_Request... X-Git-Tag: RELEASE_0_7_0~32 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=3e75fa70f5996af755acceab7302e295f99ff670 * added HTTPi_Request::unsetOptions(), HTTPi_Request::addHeader(), HTTPi_Request::addCookie() --- diff --git a/http.c b/http.c index 30711e3..32d9e2a 100644 --- a/http.c +++ b/http.c @@ -308,6 +308,10 @@ zend_function_entry httpi_request_class_methods[] = { PHP_ME(HTTPi_Request, setOptions, NULL, ZEND_ACC_PUBLIC) PHP_ME(HTTPi_Request, getOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HTTPi_Request, unsetOptions, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HTTPi_Request, addHeader, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HTTPi_Request, addCookie, NULL, ZEND_ACC_PUBLIC) PHP_ME(HTTPi_Request, setMethod, NULL, ZEND_ACC_PUBLIC) PHP_ME(HTTPi_Request, getMethod, NULL, ZEND_ACC_PUBLIC) @@ -530,7 +534,7 @@ PHP_MINFO_FUNCTION(http) php_info_print_table_row(2, "Extended HTTP support", "enabled"); php_info_print_table_row(2, "Extension Version:", full_version_string); php_info_print_table_end(); - + php_info_print_table_start(); php_info_print_table_header(2, "Functionality", "Availability"); php_info_print_table_row(2, "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HTTPi")); diff --git a/http_methods.c b/http_methods.c index 1365fcf..e4042a1 100644 --- a/http_methods.c +++ b/http_methods.c @@ -628,6 +628,73 @@ PHP_METHOD(HTTPi_Request, getOptions) } /* }}} */ +/* {{{ proto void HTTPi_Request::unsetOptions() + * + * Unset all options/headers/cookies. + */ +PHP_METHOD(HTTPi_Request, unsetOptions) +{ + getObject(httpi_request_object, obj); + + NO_ARGS; + + FREE_PARR(obj, options); + INIT_PARR(obj, options); +} +/* }}} */ + +/* {{{ proto bool HTTPi_Request::addHeader(array header) + * + * Add (a) request header name/value pair(s). + */ +PHP_METHOD(HTTPi_Request, addHeader) +{ + zval *opts, **headers, *new_headers; + getObject(httpi_request_object, obj); + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &new_headers)) { + RETURN_FALSE; + } + + opts = GET_PROP(obj, options); + + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) { + array_merge(new_headers, *headers); + } else { + zval_add_ref(new_headers); + add_assoc_zval(opts, "headers", new_headers); + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool HTTPi_Request::addCookie(array cookie) + * + * Add (a) cookie(s). + */ +PHP_METHOD(HTTPi_Request, addCookie) +{ + zval *opts, **cookies, *new_cookies; + getObject(httpi_request_object, obj); + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &new_cookies)) { + RETURN_FALSE; + } + + opts = GET_PROP(obj, options); + + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "cookies", sizeof("cookies"), (void **) &cookies)) { + array_merge(new_cookies, *cookies); + } else { + zval_add_ref(new_cookies); + add_assoc_zval(opts, "cookies", new_cookies); + } + + RETURN_TRUE; +} +/* }}} */ + /* {{{ proto bool HTTPi_Request::setURL(string url) * * Set the request URL. diff --git a/php_http.h b/php_http.h index ea2c255..3f1a6c2 100644 --- a/php_http.h +++ b/php_http.h @@ -116,6 +116,9 @@ PHP_METHOD(HTTPi_Request, __construct); PHP_METHOD(HTTPi_Request, __destruct); PHP_METHOD(HTTPi_Request, setOptions); PHP_METHOD(HTTPi_Request, getOptions); +PHP_METHOD(HTTPi_Request, unsetOptions); +PHP_METHOD(HTTPi_Request, addHeader); +PHP_METHOD(HTTPi_Request, addCookie); PHP_METHOD(HTTPi_Request, setMethod); PHP_METHOD(HTTPi_Request, getMethod); PHP_METHOD(HTTPi_Request, setURL);