+ /* decode and replace Transfer-Encoding with Content-Length header */
+ if ((*continue_at = http_encoding_dechunk(body, message + message_length - body, &decoded, &decoded_len))) {
+ zval *len;
+ char *tmp;
+ int tmp_len;
+
+ tmp_len = (int) spprintf(&tmp, 0, "%zu", decoded_len);
+ MAKE_STD_ZVAL(len);
+ ZVAL_STRINGL(len, tmp, tmp_len, 0);
+
+ ZVAL_ADDREF(c);
+ zend_hash_update(&msg->hdrs, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), (void *) &c, sizeof(zval *), NULL);
+ zend_hash_del(&msg->hdrs, "Transfer-Encoding", sizeof("Transfer-Encoding"));
+ zend_hash_del(&msg->hdrs, "Content-Length", sizeof("Content-Length"));
+ zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL);
+
+ phpstr_from_string_ex(PHPSTR(msg), decoded, decoded_len);
+ efree(decoded);
+ }
+ }
+ zval_ptr_dtor(&c);
+ }
+
+ if (!*continue_at && (c = http_message_header(msg, "Content-Length"))) {
+ /* message has content-length header */
+ ulong len = strtoul(Z_STRVAL_P(c), NULL, 10);
+ if (len > remaining) {
+ http_error_ex(HE_NOTICE, HTTP_E_MALFORMED_HEADERS, "The Content-Length header pretends a larger body than actually received (expected %lu bytes; got %lu bytes)", len, remaining);
+ len = remaining;