- phpstr_appends(&str, HTTP_CRLF);
- phpstr_append(&str, PHPSTR_VAL(msg), PHPSTR_LEN(msg));
- phpstr_appends(&str, HTTP_CRLF);
+ 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->info.request.URI, strlen(message->info.request.URI),
+ NULL, 0, host, host_len, port);
+ efree(host);
+ } else {
+ uri = http_absolute_uri(message->info.request.URI);
+ }