+}
+
+static zval *message_header_strval(zval **header TSRMLS_DC)
+{
+ zval *ret;
+
+ if (Z_TYPE_PP(header) == IS_BOOL) {
+ MAKE_STD_ZVAL(ret);
+ ZVAL_STRING(ret, Z_BVAL_PP(header) ? "true" : "false", 1);
+ } else if (Z_TYPE_PP(header) == IS_ARRAY) {
+ zval **val;
+ HashPosition pos;
+ php_http_buffer_t str;
+
+ php_http_buffer_init(&str);
+ MAKE_STD_ZVAL(ret);
+ FOREACH_VAL(pos, *header, val) {
+ zval *strval = message_header_strval(val TSRMLS_CC);
+
+ php_http_buffer_appendf(&str, PHP_HTTP_BUFFER_LEN(&str) ? ", %s":"%s", Z_STRVAL_P(strval));
+ zval_ptr_dtor(&strval);
+ }
+ php_http_buffer_fix(&str);
+ ZVAL_STRINGL(ret, PHP_HTTP_BUFFER_VAL(&str), PHP_HTTP_BUFFER_LEN(&str), 0);
+ } else {
+ ret = php_http_zsep(1, IS_STRING, *header);
+ }
+
+ return ret;
+}
+
+static 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);