if (message) {
zend_hash_destroy(&message->hdrs);
phpstr_dtor(PHPSTR(message));
- if (message->dup && message->raw.dup) {
- efree(message->raw.dup);
+ if (message->raw) {
+ efree(message->raw);
}
if (message->type == HTTP_MSG_REQUEST) {
if (message->info.request.method) {
return message;
}
-PHP_HTTP_API http_message *_http_message_parse_ex(const char *message, size_t length, zend_bool dup TSRMLS_DC)
+PHP_HTTP_API http_message *_http_message_parse_ex(char *message, size_t length, zend_bool dup TSRMLS_DC)
{
- const char *message_start = message, *body = NULL;
+ char *message_start = message, *body = NULL;
size_t message_length = length, header_length = 0;
http_message *msg;
msg = http_message_init();
+ msg->len = length;
+ msg->raw = dup ? estrndup(message, length) : message;
+
// response
if (!strncmp(message, "HTTP/1.", lenof("HTTP/1."))) {
msg->type = HTTP_MSG_RESPONSE;
message_start += lenof(HTTP_CRLF);
message_length -= message_start - message;
- if (msg->dup = dup) {
- msg->len = length;
- msg->raw.dup = estrndup(message, length);
- } else {
- msg->len = length;
- msg->raw.ptr = message;
- }
-
if (body = strstr(message_start, HTTP_CRLF HTTP_CRLF)) {
body += lenof(HTTP_CRLF HTTP_CRLF);
header_length = body - message_start;
} info;
size_t len;
- zend_bool dup;
-
- union {
- char *dup;
- const char *ptr;
- } raw;
+ char *raw;
http_message *nested;
};
#define http_message_parse(m, l) http_message_parse_ex((m), (l), 1)
#define http_message_parse_ex(m, l, d) _http_message_parse_ex((m), (l), (d) TSRMLS_CC)
-PHP_HTTP_API http_message *_http_message_parse_ex(const char *message, size_t length, zend_bool duplicate TSRMLS_DC);
+PHP_HTTP_API http_message *_http_message_parse_ex(char *message, size_t length, zend_bool duplicate TSRMLS_DC);
#define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l))
PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);