zval *qdata = NULL;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) {
- if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) {
- zend_update_property_stringl(php_http_client_request_class_entry, getThis(), ZEND_STRL("query"), "", 0 TSRMLS_CC);
- } else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) {
- char *query_data_str = NULL;
- size_t query_data_len;
-
- if (SUCCESS == php_http_url_encode_hash(HASH_OF(qdata), NULL, 0, &query_data_str, &query_data_len TSRMLS_CC)) {
- zend_update_property_stringl(php_http_client_request_class_entry, getThis(), ZEND_STRL("query"), query_data_str, query_data_len TSRMLS_CC);
- efree(query_data_str);
- }
+ php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_url *old_url = NULL, new_url = {NULL};
+ char empty[] = "";
+
+ if (qdata) {
+ zval arr, str;
+
+ INIT_PZVAL(&arr);
+ array_init(&arr);
+ INIT_PZVAL(&str);
+ ZVAL_NULL(&str);
+
+ php_http_querystring_update(&arr, qdata, &str TSRMLS_CC);
+ new_url.query = Z_STRVAL(str);
+ zval_dtor(&arr);
} else {
- zval *data = php_http_ztyp(IS_STRING, qdata);
+ new_url.query = &empty[0];
+ }
- zend_update_property_stringl(php_http_client_request_class_entry, getThis(), ZEND_STRL("query"), Z_STRVAL_P(data), Z_STRLEN_P(data) TSRMLS_CC);
- zval_ptr_dtor(&data);
+ if (obj->message->http.info.request.url) {
+ old_url = php_url_parse(obj->message->http.info.request.url);
+ efree(obj->message->http.info.request.url);
+ }
+
+ php_http_url(PHP_HTTP_URL_REPLACE, old_url, &new_url, NULL, &obj->message->http.info.request.url, NULL TSRMLS_CC);
+
+ if (old_url) {
+ php_url_free(old_url);
+ }
+ if (new_url.query != &empty[0]) {
+ STR_FREE(new_url.query);
}
}
RETVAL_ZVAL(getThis(), 1, 0);
PHP_METHOD(HttpClientRequest, getQuery)
{
if (SUCCESS == zend_parse_parameters_none()) {
- RETURN_PROP(php_http_client_request_class_entry, "query");
+ php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (obj->message->http.info.request.url) {
+ php_url *purl = php_url_parse(obj->message->http.info.request.url);
+
+ if (purl) {
+ if (purl->query) {
+ RETVAL_STRING(purl->query, 0);
+ purl->query = NULL;
+ }
+ php_url_free(purl);
+ }
+ }
}
- RETURN_FALSE;
}
PHP_METHOD(HttpClientRequest, addQuery)
{
zval *qdata;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &qdata)) {
- char *query_data_str = NULL;
- size_t query_data_len = 0;
- zval *old_qdata = php_http_ztyp(IS_STRING, zend_read_property(php_http_client_request_class_entry, getThis(), ZEND_STRL("query"), 0 TSRMLS_CC));
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &qdata)) {
+ php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_url *old_url = NULL, new_url = {NULL};
+ char empty[] = "";
+
+ zval arr, str;
- if (SUCCESS == php_http_url_encode_hash(Z_ARRVAL_P(qdata), Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data_str, &query_data_len TSRMLS_CC)) {
- zend_update_property_stringl(php_http_client_request_class_entry, getThis(), ZEND_STRL("query"), query_data_str, query_data_len TSRMLS_CC);
- efree(query_data_str);
+ INIT_PZVAL(&arr);
+ array_init(&arr);
+ INIT_PZVAL(&str);
+ ZVAL_NULL(&str);
+
+ php_http_querystring_update(&arr, qdata, &str TSRMLS_CC);
+ new_url.query = Z_STRVAL(str);
+ zval_dtor(&arr);
+
+ if (obj->message->http.info.request.url) {
+ old_url = php_url_parse(obj->message->http.info.request.url);
+ efree(obj->message->http.info.request.url);
}
- zval_ptr_dtor(&old_qdata);
+ php_http_url(PHP_HTTP_URL_JOIN_QUERY, old_url, &new_url, NULL, &obj->message->http.info.request.url, NULL TSRMLS_CC);
+
+ if (old_url) {
+ php_url_free(old_url);
+ }
+ STR_FREE(new_url.query);
}
RETVAL_ZVAL(getThis(), 1, 0);
-
}
{
PHP_HTTP_REGISTER_CLASS(http\\Client, Request, http_client_request, php_http_message_class_entry, 0);
- zend_declare_property_string(php_http_client_request_class_entry, ZEND_STRL("query"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
-
return SUCCESS;
}
TSRMLS_SET_CTX(message->ts);
php_http_message_set_type(message, type);
+ message->http.version.major = 1;
+ message->http.version.minor = 1;
zend_hash_init(&message->hdrs, 0, NULL, ZVAL_PTR_DTOR, 0);
php_http_message_body_init(&message->body, NULL TSRMLS_CC);
case PHP_HTTP_REQUEST:
if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1 TSRMLS_CC)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
php_http_version_parse(&message->http.version, Z_STRVAL_P(sval) TSRMLS_CC);
- } else {
- message->http.version.major = 1;
- message->http.version.minor = 1;
}
if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1 TSRMLS_CC))) {
message->http.info.request.method = estrdup(Z_STRVAL_P(sval));
case PHP_HTTP_RESPONSE:
if (!SG(sapi_headers).http_status_line || !php_http_info_parse((php_http_info_t *) &message->http, SG(sapi_headers).http_status_line TSRMLS_CC)) {
- message->http.version.major = 1;
- message->http.version.minor = 1;
if (!(message->http.info.response.code = SG(sapi_headers).http_response_code)) {
message->http.info.response.code = 200;
}