PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *headers, zend_bool prettify,
http_info_callback callback_func, void **callback_data TSRMLS_DC)
{
- const char *colon = NULL, *line = NULL, *begin = header;
- const char *body = http_locate_body(header);
- size_t header_len;
+ const char *colon = NULL, *line = header;
zval array;
-
- INIT_ZARR(array, headers);
- if (body) {
- header_len = body - header;
- } else {
- header_len = strlen(header) + 1;
- }
- line = header;
+ INIT_ZARR(array, headers);
- if (header_len) do {
+#define MORE_HEADERS (*(line-1) && !(*(line-1) == '\n' && (*line == '\n' || *line == '\r')))
+ do {
int value_len = 0;
+
switch (*line++)
{
case ':':
callback_func(callback_data, &headers, &i TSRMLS_CC);
http_info_dtor(&i);
Z_ARRVAL(array) = headers;
- } else
-
- /* "header: value" pair */
- if (colon) {
-
+ } else if (colon) {
+ /* "header: value" pair */
/* skip empty key */
if (header != colon) {
zval **previous = NULL;
}
efree(key);
}
+ } else if (MORE_HEADERS) {
+ return FAILURE;
}
colon = NULL;
value_len = 0;
}
break;
}
- } while (header_len > (size_t) (line - begin));
+ } while (MORE_HEADERS);
return SUCCESS;
}