- http_message *response = msg, *request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request));
- http_message *free_msg = request;
-
- do {
- char *message;
- size_t msglen;
-
- http_message_tostring(response, &message, &msglen);
- phpstr_append(&obj->history, message, msglen);
- efree(message);
-
- http_message_tostring(request, &message, &msglen);
- phpstr_append(&obj->history, message, msglen);
- efree(message);
-
- } while ((response = response->parent) && (request = request->parent));
-
- http_message_free(&free_msg);
- phpstr_fix(&obj->history);
+ http_message *response = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response));
+ http_message *request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request));
+
+ if (response && request) {
+ zval *hist, *history = GET_PROP(history);
+ http_message *hist_msg = http_message_reverse(http_message_interconnect(response, request));
+
+ MAKE_STD_ZVAL(hist);
+ ZVAL_OBJVAL(hist, http_message_object_new_ex(http_message_object_ce, hist_msg, NULL), 0);
+ if (Z_TYPE_P(history) == IS_OBJECT) {
+ http_message_object_prepend(hist, history);
+ }
+ SET_PROP(history, hist);
+ zval_ptr_dtor(&hist);
+ } else {
+ http_message_free(&response);
+ http_message_free(&request);
+ }