Browse Source

Remove X-Sendfile-Range feature; it will be replaced with something more powerful (#2005, #2008)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2542 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.23
Stefan Bühler 13 years ago
parent
commit
b2108c436c
  1. 1
      NEWS
  2. 39
      src/mod_fastcgi.c
  3. 2
      src/response.c
  4. 7
      tests/docroot/www/sendfile.php
  5. 2
      tests/lighttpd.conf
  6. 18
      tests/mod-fastcgi.t

1
NEWS

@ -53,7 +53,6 @@ NEWS
* Add support for "real" entropy from /dev/[u]random (fixes #1977)
* Adding support for additional chars in LDAP usernames (fixes #1941)
* Ignore multiple "If-None-Match" headers (only use first one, fixes #753)
* Add X-Sendfile-Range feature (fixes #2005)
* Fix 100% cpu usage if time() < 0 (thx to gaspa and cate, fixes #1964)
* Allow max-keep-alive-requests to depend on conditional (fixes #1881)
* Make dependency on svnversion/git optional (for devel versionstamp, fixes #2009)

39
src/mod_fastcgi.c

@ -2554,51 +2554,22 @@ static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
stat_cache_entry *sce;
if (HANDLER_ERROR != stat_cache_get_entry(srv, con, ds->value, &sce)) {
data_string *dcls, *dsr;
off_t start = 0, end = sce->st.st_size, len;
data_string *dcls;
if (NULL == (dcls = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) {
dcls = data_response_init();
}
/* found */
/* Assume we should serve from the beginning to the end of the file. */
/* If they gave us X-Sendfile-Range, adjust portion to serve. */
/* X-Sendfile-Range: header must include start offset, may include end offset, must end after the last offset */
if (NULL != (dsr = (data_string *) array_get_element(con->response.headers, "X-Sendfile-Range"))) {
char *end_part = NULL, *final_part = NULL;
start = strtoll(dsr->value->ptr, &end_part, 10);
if (start < 0 || end_part == ds->value->ptr) {
start = 0;
log_error_write(srv, __FILE__, __LINE__, "sb",
"Invalid X-Sendfile-Range header:",
dsr->value);
} else if (end_part && *end_part) {
end = strtoll(end_part, &final_part, 10);
if (end < 0 || end_part == final_part || !final_part || *final_part || start > end) {
start = 0;
end = sce->st.st_size;
log_error_write(srv, __FILE__, __LINE__, "sb",
"Invalid X-Sendfile-Range header:",
dsr->value);
} else {
if (end > sce->st.st_size) end = sce->st.st_size;
if (start > end) start = end;
}
} else {
if (start > end) start = end;
}
}
len = end - start;
if (len != 0) http_chunk_append_file(srv, con, ds->value, start, len);
http_chunk_append_file(srv, con, ds->value, 0, sce->st.st_size);
hctx->send_content_body = 0; /* ignore the content */
joblist_append(srv, con);
buffer_copy_string_len(dcls->key, CONST_STR_LEN("Content-Length"));
buffer_copy_off_t(dcls->value, len);
buffer_copy_string_len(dcls->key, "Content-Length", sizeof("Content-Length")-1);
buffer_copy_off_t(dcls->value, sce->st.st_size);
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 = len;
con->response.content_length = sce->st.st_size;
} else {
log_error_write(srv, __FILE__, __LINE__, "sb",
"send-file error: couldn't get stat_cache entry for:",

2
src/response.c

@ -70,7 +70,7 @@ int http_response_write_header(server *srv, connection *con) {
if (ds->value->used && ds->key->used &&
0 != strncasecmp(ds->key->ptr, CONST_STR_LEN("X-LIGHTTPD-")) &&
0 != strncasecmp(ds->key->ptr, CONST_STR_LEN("X-Sendfile"))) {
0 != strcasecmp(ds->key->ptr, "X-Sendfile")) {
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;

7
tests/docroot/www/sendfile.php

@ -1,7 +0,0 @@
<?php
header("X-Sendfile: " . getcwd() . "/index.txt");
if ($_GET["range"]) header("X-Sendfile-Range: " . $_GET["range"]);
?>

2
tests/lighttpd.conf

@ -82,7 +82,7 @@ $HTTP["url"] =~ "\.pdf$" {
}
fastcgi.debug = 0
fastcgi.server = ( ".php" => ( ( "host" => "127.0.0.1", "port" => 1026, "broken-scriptfilename" => "enable", "allow-x-send-file" => "enable" ) ),
fastcgi.server = ( ".php" => ( ( "host" => "127.0.0.1", "port" => 1026, "broken-scriptfilename" => "enable" ) ),
"/prefix.fcgi" => ( ( "host" => "127.0.0.1", "port" => 1026, "check-local" => "disable", "broken-scriptfilename" => "enable" ) )
)

18
tests/mod-fastcgi.t

@ -7,7 +7,7 @@ BEGIN {
}
use strict;
use Test::More tests => 55;
use Test::More tests => 53;
use LightyTest;
my $tf = LightyTest->new();
@ -25,7 +25,7 @@ SKIP: {
}
SKIP: {
skip "no PHP running on port 1026", 32 unless $tf->listening_on(1026);
skip "no PHP running on port 1026", 30 unless $tf->listening_on(1026);
ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
@ -174,20 +174,6 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ];
ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
$t->{REQUEST} = ( <<EOF
GET /sendfile.php HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ];
ok($tf->handle_http($t) == 0, 'X-Sendfile');
$t->{REQUEST} = ( <<EOF
GET /sendfile.php?range=3+10 HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'OCTYPE ' } ];
ok($tf->handle_http($t) == 0, 'X-Sendfile-Range');
ok($tf->stop_proc == 0, "Stopping lighttpd");

Loading…
Cancel
Save