- while (isspace(colon[value_len - 1])) --value_len;
-
- if (value_len > 0) {
- value = estrndup(colon, value_len);
- } else {
- value = estrdup("");
- value_len = 0;
- }
-
- /* if we already have got such a header make an array of those */
- if (SUCCESS == zend_hash_find(headers, key, keylen + 1, (void **) &previous)) {
- /* convert to array */
- if (Z_TYPE_PP(previous) != IS_ARRAY) {
- convert_to_array(*previous);
+ while (keylen && HTTP_IS_CTYPE(space, key[keylen - 1])) --keylen;
+
+ if (keylen > 0) {
+ zval **previous = NULL;
+ char *value;
+ char *keydup = estrndup(key, keylen);
+
+ if (prettify) {
+ keydup = pretty_key(keydup, keylen, 1, 1);
+ }
+
+ value_len += line - colon - 1;
+
+ /* skip leading ws */
+ while (HTTP_IS_CTYPE(space, *(++colon))) --value_len;
+ /* skip trailing ws */
+ while (HTTP_IS_CTYPE(space, colon[value_len - 1])) --value_len;
+
+ if (value_len > 0) {
+ value = estrndup(colon, value_len);
+ } else {
+ value = estrdup("");
+ value_len = 0;
+ }
+
+ /* if we already have got such a header make an array of those */
+ if (SUCCESS == zend_hash_find(headers, keydup, keylen + 1, (void *) &previous)) {
+ /* convert to array */
+ if (Z_TYPE_PP(previous) != IS_ARRAY) {
+ convert_to_array(*previous);
+ }
+ add_next_index_stringl(*previous, value, value_len, 0);
+ } else {
+ add_assoc_stringl(&array, keydup, value, value_len, 0);