Project

General

Profile

Feature #2005 ยป x-sendfile-range.patch

r2522 patch to add X-Sendfile-Range header support to 1.4.x. - shellsage, 2009-06-11 06:07

View differences:

src/mod_fastcgi.c (working copy)
dcls = data_response_init();
}
/* found */
http_chunk_append_file(srv, con, ds->value, 0, sce->st.st_size);
/* Assume we should serve from the beginning to the end of the file. */
/* If they gave us X-Sendfile-Range, adjust portion to serve. */
long start = 0;
long end = sce->st.st_size;
data_string *dsr;
if (NULL != (dsr = (data_string *) array_get_element(con->response.headers, "X-Sendfile-Range"))) {
char *range_part = strtok(dsr->value->ptr, " ");
int on_start = 1;
while(range_part != NULL) {
if(on_start == 1) {
start = atol(range_part);
} else {
end = atol(range_part);
break;
}
on_start = 0;
range_part = strtok(NULL, " ");
}
if(end > sce->st.st_size) {
end = sce->st.st_size;
}
}
long length = end - start;
http_chunk_append_file(srv, con, ds->value, start, end);
hctx->send_content_body = 0; /* ignore the content */
joblist_append(srv, con);
buffer_copy_string_len(dcls->key, "Content-Length", sizeof("Content-Length")-1);
buffer_copy_off_t(dcls->value, sce->st.st_size);
buffer_copy_off_t(dcls->value, length);
dcls = (data_string*) array_replace(con->response.headers, (data_unset *)dcls);
if (dcls) dcls->free((data_unset*)dcls);
con->parsed_response |= HTTP_CONTENT_LENGTH;
con->response.content_length = sce->st.st_size;
con->response.content_length = length;
} else {
log_error_write(srv, __FILE__, __LINE__, "sb",
"send-file error: couldn't get stat_cache entry for:",
src/response.c (working copy)
if (ds->value->used && ds->key->used &&
0 != strncasecmp(ds->key->ptr, CONST_STR_LEN("X-LIGHTTPD-")) &&
0 != strcasecmp(ds->key->ptr, "X-Sendfile")) {
0 != strcasecmp(ds->key->ptr, "X-Sendfile") &&
0 != strcasecmp(ds->key->ptr, "X-Sendfile-Range")) {
if (0 == strcasecmp(ds->key->ptr, "Date")) have_date = 1;
if (0 == strcasecmp(ds->key->ptr, "Server")) have_server = 1;
if (0 == strcasecmp(ds->key->ptr, "Content-Encoding") && 304 == con->http_status) continue;
    (1-1/1)