[core] server.error_handler_404 X-Sendfile ENOENT (#2474)

Better handling if server.error_handler_404 is a dynamic handler which
returns X-Sendfile pointing to a file which does not exist

(server.error_handler_404 historically did not reset con->file_started,
 and for mod_fastcgi, an X-Sendfile failure in the error handler would
 result in an empty response body.)

x-ref:
  "Option to map send-file file-not-found error to normal 404"
  https://redmine.lighttpd.net/issues/2474
This commit is contained in:
Glenn Strauss 2017-06-19 00:45:56 -04:00
parent 55867b5602
commit ddf339569c
1 changed files with 3 additions and 0 deletions

View File

@ -1268,6 +1268,7 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons
if (opts->local_redir && con->http_status >= 300 && con->http_status < 400){
/*(con->parsed_response & HTTP_LOCATION)*/
handler_t rc = http_response_process_local_redir(srv, con, blen);
if (con->mode == DIRECT) con->file_started = 0;
if (rc != HANDLER_GO_ON) return rc;
}
@ -1278,12 +1279,14 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons
&& NULL != (ds = (data_string *) array_get_element(con->response.headers, "X-Sendfile2"))) {
http_response_xsendfile2(srv, con, ds->value, opts->xsendfile_docroot);
buffer_reset(ds->value); /*(do not send to client)*/
if (con->mode == DIRECT) con->file_started = 0;
return HANDLER_FINISHED;
} else if (NULL != (ds = (data_string *) array_get_element(con->response.headers, "X-Sendfile"))
|| (opts->backend == BACKEND_FASTCGI /* X-LIGHTTPD-send-file is deprecated; historical for fastcgi */
&& NULL != (ds = (data_string *) array_get_element(con->response.headers, "X-LIGHTTPD-send-file")))) {
http_response_xsendfile(srv, con, ds->value, opts->xsendfile_docroot);
buffer_reset(ds->value); /*(do not send to client)*/
if (con->mode == DIRECT) con->file_started = 0;
return HANDLER_FINISHED;
}
}