HTTP_ARG_VAL(info, 1)
HTTP_END_ARGS;
+HTTP_BEGIN_ARGS(putData, 2)
+ 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)
HTTP_ARG_VAL(url, 0)
HTTP_ARG_VAL(file, 0)
HTTP_ARG_VAL(method, 0)
HTTP_END_ARGS;
+HTTP_BEGIN_ARGS(encodeBody, 2)
+ HTTP_ARG_VAL(fields, 0)
+ HTTP_ARG_VAL(files, 0)
+HTTP_END_ARGS;
+
#define OBJ_PROP_CE http_request_object_ce
zend_class_entry *http_request_object_ce;
zend_function_entry http_request_object_fe[] = {
HTTP_REQUEST_ALIAS(head, http_head)
HTTP_REQUEST_ALIAS(postData, http_post_data)
HTTP_REQUEST_ALIAS(postFields, http_post_fields)
+ HTTP_REQUEST_ALIAS(putData, http_put_data)
HTTP_REQUEST_ALIAS(putFile, http_put_file)
HTTP_REQUEST_ALIAS(putStream, http_put_stream)
HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister)
HTTP_REQUEST_ALIAS(methodName, http_request_method_name)
HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists)
+
+ HTTP_REQUEST_ALIAS(encodeBody, http_request_body_encode)
EMPTY_FUNCTION_ENTRY
};
}
ALLOC_HASHTABLE(OBJ_PROP(o));
- zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
ov.handle = putObject(http_request_object, o);
zval **headers, *opts = GET_PROP(options);
if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
- (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void *) &headers)) &&
(Z_TYPE_PP(headers) == IS_ARRAY)) {
zval **ct_header;
/* only override if not already set */
- if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void **) &ct_header))) {
+ if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void *) &ct_header))) {
add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
} else
/* or not a string, zero length string or a string of spaces */
zval **entry, *pcb;
if ( (Z_TYPE_P(options) != IS_ARRAY)
- || (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void **) &entry)
+ || (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void *) &entry)
|| (!zval_is_true(*entry)))) {
MAKE_STD_ZVAL(pcb);
array_init(pcb);
}
UPD_PROP(long, responseCode, msg->http.info.response.code);
- UPD_PROP(string, responseStatus, msg->http.info.response.status);
+ UPD_PROP(string, responseStatus, msg->http.info.response.status ? msg->http.info.response.status : "");
MAKE_STD_ZVAL(resp);
array_init(resp);
ret = FAILURE;
}
- if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
+ if (!EG(exception) && zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
zval *param;
MAKE_STD_ZVAL(param);
ZVAL_BOOL(param, ret == SUCCESS);
- zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL, param);
+ with_error_handling(EH_NORMAL, NULL) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL, param);
+ } end_error_handling();
zval_ptr_dtor(¶m);
}
if (prettify_keys && opts) {
zend_hash_apply_with_arguments(Z_ARRVAL_P(opts), apply_pretty_key, 0);
}
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), key, len, (void **) &entry)) {
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), key, len, (void *) &entry)) {
if (overwrite) {
zend_hash_clean(Z_ARRVAL_PP(entry));
}
array_init(return_value);
if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
- (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options))) {
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void *) &options))) {
convert_to_array(*options);
array_copy(*options, return_value);
}
data = GET_PROP(responseData);
if ( (Z_TYPE_P(data) == IS_ARRAY) &&
- (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void *) &headers)) &&
(Z_TYPE_PP(headers) == IS_ARRAY)) {
if (!header_len || !header_name) {
RETVAL_ZVAL(*headers, 1, 0);
- } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void **) &header)) {
+ } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void *) &header)) {
RETVAL_ZVAL(*header, 1, 0);
} else {
RETVAL_FALSE;
data = GET_PROP(responseData);
if ( (Z_TYPE_P(data) == IS_ARRAY) &&
- (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void *) &headers)) &&
(Z_TYPE_PP(headers) == IS_ARRAY)) {
int i = 0;
ulong idx = 0;
zval *data = GET_PROP(responseData);
if ( (Z_TYPE_P(data) == IS_ARRAY) &&
- (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body))) {
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void *) &body))) {
RETURN_ZVAL(*body, 1, 0);
} else {
RETURN_FALSE;
}
if (info_len && info_name) {
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void **) &infop)) {
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void *) &infop)) {
RETURN_ZVAL(*infop, 1, 0);
} else {
http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Could not find response info named %s", info_name);
* to access the data of previously received responses within this request
* cycle.
*
- * Throws HttpException.
+ * Throws HttpException, HttpRuntimeException.
*/
PHP_METHOD(HttpRequest, getResponseMessage)
{
- NO_ARGS;
-
- IF_RETVAL_USED {
+ NO_ARGS {
zval *message;
SET_EH_THROW_HTTP();
if (Z_TYPE_P(message) == IS_OBJECT) {
RETVAL_OBJECT(message, 1);
} else {
- RETVAL_NULL();
+ http_error(HE_WARNING, HTTP_E_RUNTIME, "HttpRequest does not contain a response message");
}
SET_EH_NORMAL();
}
* Get sent HTTP message.
*
* Returns an HttpMessage in a form of a string
- *
*/
PHP_METHOD(HttpRequest, getRawRequestMessage)
{
* Get the entire HTTP response.
*
* Returns the complete web server response, including the headers in a form of a string.
- *
*/
PHP_METHOD(HttpRequest, getRawResponseMessage)
{