+ phpstr_init(&preface);
+ 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)) {
+
+#define HTTP_RANGE_PREFACE \
+ HTTP_CRLF "--%s" \
+ HTTP_CRLF "Content-Type: %s" \
+ HTTP_CRLF "Content-Range: bytes %ld-%ld/%zu" \
+ HTTP_CRLF HTTP_CRLF
+
+ phpstr_appendf(&preface, HTTP_RANGE_PREFACE, boundary_str, content_type, Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size);
+ phpstr_fix(&preface);
+ http_send_response_data_plain(&s, PHPSTR_VAL(&preface), PHPSTR_LEN(&preface));
+ phpstr_reset(&preface);
+ http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1);
+ }
+ }
+ phpstr_dtor(&preface);
+
+ http_send_response_data_plain(&s, HTTP_CRLF "--", lenof(HTTP_CRLF "--"));
+ http_send_response_data_plain(&s, boundary_str, boundary_len);
+ http_send_response_data_plain(&s, "--", lenof("--"));
+
+ http_send_response_finish(&s);
+ zend_hash_destroy(&ranges);
+ return SUCCESS;
+ }
+ }
+ case RANGE_NO:
+ {
+ zend_hash_destroy(&ranges);
+
+ /* send 304 Not Modified if etag matches - DON'T return on ETag generation failure */
+ if (!no_cache && (http_interrupt_ob_etaghandler() || (HTTP_G->send.unquoted_etag != NULL))) {
+ char *etag = NULL;
+
+ if (HTTP_G->send.unquoted_etag) {
+ etag = estrdup(HTTP_G->send.unquoted_etag);
+ }
+
+ if (etag || (etag = http_etag(data_ptr, data_size, data_mode))) {
+ char *sent_header = NULL;
+
+ http_send_etag_ex(etag, strlen(etag), &sent_header);
+ if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
+ return http_exit_ex(304, sent_header, NULL, 0);
+ } else {
+ STR_FREE(sent_header);
+ /* no caching for Last-Modified if ETags really don't match */
+ no_cache = http_got_server_var("HTTP_IF_NONE_MATCH");
+ }
+ efree(etag);
+ }
+ }
+
+ /* send 304 Not Modified if last modified matches */
+ if (!no_cache && HTTP_G->send.last_modified && http_match_last_modified("HTTP_IF_MODIFIED_SINCE", HTTP_G->send.last_modified)) {
+ char *sent_header = NULL;
+ http_send_last_modified_ex(HTTP_G->send.last_modified, &sent_header);
+ return http_exit_ex(304, sent_header, NULL, 0);
+ }
+
+ /* send full response */
+ http_send_response_start(&s, data_size);
+ http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, 0, data_size);
+ http_send_response_finish(&s);
+ return SUCCESS;