- http_send_response_start(&s, 0);
-
- if (!content_type) {
- content_type = "application/x-octetstream";
- }
-
- FOREACH_HASH_VAL(pos, &ranges, range) {
- if ( SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void **) &begin) &&
- SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void **) &end)) {
- char preface_str[512];
- size_t preface_len;
+ http_send_response_start(&s, Z_LVAL_PP(end)-Z_LVAL_PP(begin)+1);
+ http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1);
+ http_send_response_finish(&s);
+ zend_hash_destroy(&ranges);
+ return SUCCESS;
+ }
+ } else {
+ /* multi range */
+ HashPosition pos;
+ zval **range, **begin, **end;
+ const char *content_type = HTTP_G->send.content_type;
+ char boundary_str[32], range_header_str[256];
+ size_t boundary_len, range_header_len;
+
+ boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) HTTP_GET_REQUEST_TIME(), (float) php_combined_lcg(TSRMLS_C));
+ range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Type: multipart/byteranges; boundary=%s", boundary_str);
+
+ http_send_status_header_ex(206, range_header_str, range_header_len, 1);
+ http_send_response_start(&s, 0);
+
+ if (!content_type) {
+ content_type = "application/x-octetstream";
+ }
+
+ FOREACH_HASH_VAL(pos, &ranges, range) {
+ if ( SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void **) &begin) &&
+ SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void **) &end)) {
+ char preface_str[512];
+ size_t preface_len;