} else if (ops->rsrc) {
h->rf = php_http_resource_factory_init(NULL, h->ops->rsrc, h, NULL);
}
- h->buffer = php_http_buffer_init(NULL);
- h->parser = php_http_message_parser_init(NULL TSRMLS_CC);
- h->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ h->request.buffer = php_http_buffer_init(NULL);
+ h->request.parser = php_http_message_parser_init(NULL TSRMLS_CC);
+ h->request.message = php_http_message_init(NULL, 0 TSRMLS_CC);
+
+ h->response.buffer = php_http_buffer_init(NULL);
+ h->response.parser = php_http_message_parser_init(NULL TSRMLS_CC);
+ h->response.message = php_http_message_init(NULL, 0 TSRMLS_CC);
TSRMLS_SET_CTX(h->ts);
php_http_resource_factory_free(&h->rf);
- php_http_message_parser_free(&h->parser);
- php_http_message_free(&h->message);
- php_http_buffer_free(&h->buffer);
+ php_http_message_parser_free(&h->request.parser);
+ php_http_message_free(&h->request.message);
+ php_http_buffer_free(&h->request.buffer);
+
+ php_http_message_parser_free(&h->response.parser);
+ php_http_message_free(&h->response.message);
+ php_http_buffer_free(&h->response.buffer);
}
PHP_HTTP_API void php_http_client_free(php_http_client_t **h)
} else if (to->ops->rsrc){
to->rf = php_http_resource_factory_init(NULL, to->ops->rsrc, to, NULL);
}
- to->buffer = php_http_buffer_init(NULL);
- to->parser = php_http_message_parser_init(NULL TSRMLS_CC);
- to->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+
+ to->request.buffer = php_http_buffer_init(NULL);
+ to->request.parser = php_http_message_parser_init(NULL TSRMLS_CC);
+ to->request.message = php_http_message_init(NULL, 0 TSRMLS_CC);
+
+ to->response.buffer = php_http_buffer_init(NULL);
+ to->response.parser = php_http_message_parser_init(NULL TSRMLS_CC);
+ to->response.message = php_http_message_init(NULL, 0 TSRMLS_CC);
TSRMLS_SET_CTX(to->ts);
php_http_client_reset(obj->client);
/* reset transfer info */
- zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("info") TSRMLS_CC);
+ zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("transferInfo") TSRMLS_CC);
/* set client options */
zoptions = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("options"), 0 TSRMLS_CC);
zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("transferInfo"), info TSRMLS_CC);
zval_ptr_dtor(&info);
- if ((msg = obj->client->message)) {
- /* update history */
+ 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);
zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("responseMessage"), message TSRMLS_CC);
zval_ptr_dtor(&message);
- obj->client->message = php_http_message_init(NULL, 0 TSRMLS_CC);
- msg = msg->parent;
+ obj->client->response.message = php_http_message_init(NULL, 0 TSRMLS_CC);
} else {
zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("responseMessage") TSRMLS_CC);
}
zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("responseMessage") TSRMLS_CC);
}
- /* there might be a 100-Continue response in between */
- while (msg && !PHP_HTTP_MESSAGE_TYPE(REQUEST, msg)) {
- msg = msg->parent;
- }
-
- if (PHP_HTTP_MESSAGE_TYPE(REQUEST, msg)) {
- zval *message;
+ if ((msg = obj->client->request.message)) {
+ if (PHP_HTTP_MESSAGE_TYPE(REQUEST, msg)) {
+ zval *message;
- /* 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);
- zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("requestMessage"), message TSRMLS_CC);
- zval_ptr_dtor(&message);
+ /* 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);
+ 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);
+ }
}
if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress)) {
switch (type) {
case CURLINFO_HEADER_IN:
case CURLINFO_DATA_IN:
- case CURLINFO_HEADER_OUT:
- case CURLINFO_DATA_OUT:
- php_http_buffer_append(h->buffer, data, length);
+ php_http_buffer_append(h->response.buffer, data, length);
if (curl->options.redirects) {
flags |= PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS;
}
- if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse(h->parser, h->buffer, flags, &h->message)) {
+ if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse(h->response.parser, h->response.buffer, flags, &h->response.message)) {
+ return -1;
+ }
+ break;
+
+ case CURLINFO_HEADER_OUT:
+ case CURLINFO_DATA_OUT:
+ php_http_buffer_append(h->request.buffer, data, length);
+
+ if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse(h->request.parser, h->request.buffer, flags, &h->request.message)) {
return -1;
}
break;
}
/* request headers */
+ php_http_message_update_headers(msg);
if (zend_hash_num_elements(&msg->hdrs)) {
php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0);
zval **header_val;
}
}
-static inline void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
+PHP_HTTP_API void php_http_message_update_headers(php_http_message_t *msg)
{
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- HashPosition pos1;
- zval **header, *h;
+ zval *h;
size_t size;
TSRMLS_FETCH_FROM_CTX(msg->ts);
- switch (msg->type) {
- case PHP_HTTP_REQUEST:
- php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, PHP_HTTP_CRLF));
- break;
-
- case PHP_HTTP_RESPONSE:
- php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, PHP_HTTP_CRLF));
- break;
-
- default:
- break;
- }
-
if ((size = php_http_message_body_size(&msg->body))) {
MAKE_STD_ZVAL(h);
ZVAL_LONG(h, size);
}
}
}
+}
+static inline void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
+{
+ php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ HashPosition pos1;
+ zval **header;
+ TSRMLS_FETCH_FROM_CTX(msg->ts);
+
+ switch (msg->type) {
+ case PHP_HTTP_REQUEST:
+ php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, PHP_HTTP_CRLF));
+ break;
+
+ case PHP_HTTP_RESPONSE:
+ php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, PHP_HTTP_CRLF));
+ break;
+
+ default:
+ break;
+ }
+
+ php_http_message_update_headers(msg);
FOREACH_HASH_KEYVAL(pos1, &msg->hdrs, key, header) {
if (key.type == HASH_KEY_IS_STRING) {
PHP_HTTP_ARG_VAL(callback, 0)
PHP_HTTP_END_ARGS;
+PHP_HTTP_EMPTY_ARGS(getResource);
+
PHP_HTTP_BEGIN_ARGS(append, 1)
PHP_HTTP_ARG_VAL(string, 0)
PHP_HTTP_END_ARGS;
PHP_MALIAS(HttpMessageBody, toString, __toString, args_for_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
PHP_HTTP_MESSAGE_BODY_ME(toStream, ZEND_ACC_PUBLIC)
PHP_HTTP_MESSAGE_BODY_ME(toCallback, ZEND_ACC_PUBLIC)
+ PHP_HTTP_MESSAGE_BODY_ME(getResource, ZEND_ACC_PUBLIC)
PHP_HTTP_MESSAGE_BODY_ME(append, ZEND_ACC_PUBLIC)
PHP_HTTP_MESSAGE_BODY_ME(addForm, ZEND_ACC_PUBLIC)
PHP_HTTP_MESSAGE_BODY_ME(addPart, ZEND_ACC_PUBLIC)
RETURN_FALSE;
}
+PHP_METHOD(HttpMessageBody, getResource)
+{
+ if (SUCCESS == zend_parse_parameters_none()) {
+ php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ RETVAL_RESOURCE(obj->body->stream_id);
+ }
+}
+
PHP_METHOD(HttpMessageBody, append)
{
char *str;