+ add_assoc_zval(&strct, "parentMessage", parent);
+ http_message_tostruct_recursive(msg->parent, parent);
+ zval_ptr_dtor(&parent);
+ } else {
+ add_assoc_null(&strct, "parentMessage");
+ }
+}
+
+PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC)
+{
+ STATUS rs = FAILURE;
+
+ switch (message->type)
+ {
+ case HTTP_MSG_RESPONSE:
+ {
+ char *key;
+ ulong idx;
+ zval **val;
+
+ FOREACH_HASH_KEYVAL(&message->hdrs, key, idx, val) {
+ if (key) {
+ if (Z_TYPE_PP(val) == IS_ARRAY) {
+ zend_bool first = 1;
+ zval **data;
+
+ FOREACH_VAL(*val, data) {
+ http_send_header_ex(key, strlen(key), Z_STRVAL_PP(data), Z_STRLEN_PP(data), first, NULL);
+ first = 0;
+ }
+ } else {
+ http_send_header_ex(key, strlen(key), Z_STRVAL_PP(val), Z_STRLEN_PP(val), 1, NULL);
+ }
+ key = NULL;
+ }
+ }
+ rs = SUCCESS == http_send_status(message->http.info.response.code) &&
+ SUCCESS == http_send_data(PHPSTR_VAL(message), PHPSTR_LEN(message)) ?
+ SUCCESS : FAILURE;
+ }
+ break;
+
+ case HTTP_MSG_REQUEST:
+ {
+#ifdef HTTP_HAVE_CURL
+ char *uri = NULL;
+ zval **zhost, options, headers;
+
+ array_init(&options);
+ array_init(&headers);
+ zend_hash_copy(Z_ARRVAL(headers), &message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ add_assoc_zval(&options, "headers", &headers);
+
+ /* check host header */
+ if (SUCCESS == zend_hash_find(&message->hdrs, "Host", sizeof("Host"), (void **) &zhost)) {
+ char *colon = NULL, *host = NULL;
+ size_t host_len = 0;
+ int port = 0;
+
+ /* check for port */
+ if (colon = strchr(Z_STRVAL_PP(zhost), ':')) {
+ port = atoi(colon + 1);
+ host = estrndup(Z_STRVAL_PP(zhost), host_len = (Z_STRVAL_PP(zhost) - colon - 1));
+ } else {
+ host = estrndup(Z_STRVAL_PP(zhost), host_len = Z_STRLEN_PP(zhost));
+ }
+ uri = http_absolute_uri_ex(
+ message->http.info.request.URI, strlen(message->http.info.request.URI),
+ NULL, 0, host, host_len, port);
+ efree(host);
+ } else {
+ uri = http_absolute_uri(message->http.info.request.URI);