#include "php_http_api.h"
#include <ext/spl/spl_observer.h>
+#include <ext/standard/php_array.h>
PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC)
{
o = ecalloc(1, sizeof(*o));
zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
object_properties_init((zend_object *) o, ce);
-
+
ov.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC);
ov.handlers = &php_http_client_object_handlers;
php_http_client_object_t *obj = zend_object_store_get_object(zclient TSRMLS_CC);
php_http_client_progress_t *progress;
zval *zoptions;
+ HashTable options;
/* do we have a valid request? */
if (*zreq) {
/* reset transfer info */
zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("transferInfo") TSRMLS_CC);
+
/* set client options */
+ zend_hash_init(&options, 0, NULL, ZVAL_PTR_DTOR, 0);
zoptions = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("options"), 0 TSRMLS_CC);
- php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, Z_ARRVAL_P(zoptions));
- /* set request options */
+ if (Z_TYPE_P(zoptions) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(zoptions))) {
+ php_array_merge(&options, Z_ARRVAL_P(zoptions), 1 TSRMLS_CC);
+ }
zoptions = zend_read_property(php_http_client_request_get_class_entry(), *zreq, ZEND_STRL("options"), 0 TSRMLS_CC);
- php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, Z_ARRVAL_P(zoptions));
+ if (Z_TYPE_P(zoptions) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(zoptions))) {
+ php_array_merge(&options, Z_ARRVAL_P(zoptions), 1 TSRMLS_CC);
+ }
+ php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, &options);
+ zend_hash_destroy(&options);
/* set progress callback */
if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress)) {
zval_ptr_dtor(&info);
if ((msg = obj->client->response.message)) {
- /* FIXME: update history */
if (i_zend_is_true(zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) {
zval *new_hist, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0 TSRMLS_CC);
- zend_object_value ov = php_http_client_object_message(zclient, php_http_message_copy(msg, NULL) TSRMLS_CC);
+ php_http_message_t *zipped = php_http_message_zip(obj->client->response.message, obj->client->request.message);
+ zend_object_value ov = php_http_client_object_message(zclient, zipped TSRMLS_CC);
MAKE_STD_ZVAL(new_hist);
ZVAL_OBJVAL(new_hist, ov, 0);
/* update the actual request message */
MAKE_STD_ZVAL(message);
- ZVAL_OBJVAL(message, php_http_message_object_new_ex(php_http_message_get_class_entry(), php_http_message_copy_ex(msg, NULL, 0), NULL TSRMLS_CC), 0);
+ ZVAL_OBJVAL(message, php_http_message_object_new_ex(php_http_message_get_class_entry(), msg, NULL TSRMLS_CC), 0);
zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("requestMessage"), message TSRMLS_CC);
zval_ptr_dtor(&message);
obj->client->request.message = php_http_message_init(NULL, 0 TSRMLS_CC);
zval *opts = NULL;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+ php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 0 TSRMLS_CC);
RETVAL_ZVAL(getThis(), 1, 0);
}
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a!z!a!/", &meth_str, &meth_len, &url_str, &url_len, &zheader, &zbody, &zoptions)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
php_http_message_object_t *msg_obj;
zend_object_value ov;
zval *req, *res = NULL;
RETVAL_FALSE;
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O!", &zreq, php_http_client_request_get_class_entry())) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!", &zreq, php_http_client_request_get_class_entry())) {
if (SUCCESS == php_http_client_object_handle_request(getThis(), &zreq TSRMLS_CC)) {
php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
php_http_message_object_t *req = zend_object_store_get_object(zreq TSRMLS_CC);