Commit Graph

145 Commits

Author SHA1 Message Date
Glenn Strauss 4b0c822ed0 always poll for client POLLHUP/POLLERR events (fixes #399)
to detect client disconnect.  Do so even when waiting on backend,
and not polling for POLLRD or POLLWR on client connection.

This reduces unnecessary load on backends when backends are slow
to respond and client has given up waiting.

x-ref:
  "https://redmine.lighttpd.net/issues/399"
  FastCGI performance on high load
2016-04-18 06:19:03 -04:00
Glenn Strauss 635ab6f802 mv funcs from connections.c to connections-glue.c
connection_handle_read()
connection_handle_read_ssl()
connection_handle_read_post_state()

no code changes besides making connection_handle_read() public
(by removing 'static' and adding to connections.h)
2016-04-18 06:19:03 -04:00
Glenn Strauss c263bc6a11 defer reading request body until handle subrequest (fixes #2541)
read request body right before calling subrequest handler,
allowing request to be handled prior to reading request body,
e.g. to send 401 Unauthorized response when authentication is required

(In the future, this might move into each dynamic handler which supports
 request body (mod_cgi, mod_fastcgi, mod_proxy, mod_scgi, mod_webdav) so
 that each dynamic handler can choose whether or not to buffer request
 body or to stream request body to backend as request body is received.)

keep-alive is disabled if request body has not been completely read
prior to sending response

x-ref:
  "HTTP 401 Unauthorized only sent back after full POST request is read"
  https://redmine.lighttpd.net/issues/2541
2016-04-18 06:19:03 -04:00
Glenn Strauss a65c57a548 [core] open fd when appending file to cq (fixes #2655)
http_chunk_append_file() opens fd when appending file to chunkqueue.
Defers calculation of content length until response is finished.

This reduces race conditions pertaining to stat() and then (later)
open(), when the result of the stat() was used for Content-Length
or to generate chunked headers.

Note: this does not change how lighttpd handles files that are modified
in-place by another process after having been opened by lighttpd --
don't do that.  This *does* improve handling of files that are
frequently modified via a temporary file and then atomically renamed
into place.

mod_fastcgi has been modified to use http_chunk_append_file_range() with
X-Sendfile2 and will open the target file multiple times if there are
multiple ranges.

Note: (future todo) not implemented for chunk.[ch] interfaces used by
range requests in mod_staticfile or by mod_ssi.  Those uses could lead
to too many open fds.  For mod_staticfile, limits should be put in place
for max number of ranges accepted by mod_staticfile.  For mod_ssi,
limits would need to be placed on the maximum number of includes, and
the primary SSI file split across lots of SSI directives should either
copy the pieces or perhaps chunk.h could be extended to allow for an
open fd to be shared across multiple chunks.  Doing either of these
would improve the performance of SSI since they would replace many file
opens on the pieces of the SSI file around the SSI directives.

x-ref:
  "Serving a file that is getting updated can cause an empty response or incorrect content-length error"
  https://redmine.lighttpd.net/issues/2655

github:
Closes #49
2016-04-18 04:27:08 -04:00
Glenn Strauss 760baed402 [mod_expire] reset caching response headers for error docs (fixes #1919)
remove Cache-Control and Expires headers before handling error docs
(caching headers may have been set by mod_expire before http status
 was determined to be an error)

x-ref:
  "mod_expires sends headers on 404 responses"
  https://redmine.lighttpd.net/issues/1919
2016-04-13 01:04:39 -04:00
Glenn Strauss 8abd06a7ff consistent inclusion of config.h at top of files (fixes #2073)
From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3113 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-03-19 15:14:35 +00:00
Stefan Bühler 6f89a8bbef [core] fix request_start in keep-alive requests to mark time when received first byte (fixes #2412)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3111 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-03-19 15:01:21 +00:00
Stefan Bühler c033a1966e [core] improve conditional enabling (thx Gwenlliana, #2598)
instead of looping over all config blocks for each conditional var that
gets enabled, enable them all and run over them once.

Right now it seems we actually set all variables at once in normal
config handling (SNI only sets a subset); future modifications
might introduce new variables which are activated at a later stage
(physical path related for example).

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3083 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-02-21 18:32:17 +00:00
Stefan Bühler 566cf8decb add force_assert for more allocation results
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3072 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-01-30 13:59:07 +00:00
Stefan Bühler a069548370 [core] revert increase of temp file size back to 1MB, provide a configure option "server.upload-temp-file-size" instead (fixes #2680)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3050 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-11-07 12:51:14 +00:00
Stefan Bühler f19128086c [core] don't buffer request bodies smaller than 64k on disk
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3046 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-10-13 19:46:04 +00:00
Stefan Bühler a93be99441 [core] fix search for header end if split across chunks (fixes #2670)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3043 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-09-24 06:03:40 +00:00
Stefan Bühler 3512b5cb77 [core] allocate at least 4k buffer for incoming data
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3042 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-09-24 06:03:38 +00:00
Stefan Bühler 26226271de maintain cq->bytes_in in chunk API; keep bytes_out/bytes_in synced
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3016 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-08-22 17:04:02 +00:00
Stefan Bühler 593599f14a rewrite network (write) backends
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3012 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-08-22 16:00:59 +00:00
Stefan Bühler ad3e93ea96 Use buffer API to read and modify "used" member
- a lot of code tried to handle manually adding terminating zeroes and
  keeping track of the correct "used" count.
  Replaced all "external" usages with simple wrapper functions:
  * buffer_string_is_empty (used <= 1), buffer_is_empty (used == 0);
    prefer buffer_string_is_empty
  * buffer_string_set_length
  * buffer_string_length
  * CONST_BUF_LEN() macro
- removed "static" buffer hacks (buffers pointing to constant/stack
  memory instead of malloc()ed data)
- buffer_append_strftime(): refactor buffer+strftime uses
- li_tohex(): no need for a buffer for binary-to-hex conversion:
  the output data length is easy to predict
- remove "-Winline" from extra warnings: the "inline" keyword just
  supresses the warning about unused but defined (static) functions;
  don't care whether it actually gets inlined or not.

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2979 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 19:10:44 +00:00
Stefan Bühler 1be163b44a Remove chunkqueue_get_{append,prepend}* API
Although those were "easy" to use, they violated the abstraction:
  content of the chunkqueue should only be modified via the API.
  Replace with chunkqueue_get_memory() and chunkqueue_use_memory() for
  functions that read data from network (reusing large buffers),
  chunkqueue_steal_with_tempfiles() to store request bodies on disk
  temporarily.
  Modules that were generating content and need a buffer maintain the
  buffer manually (have to be careful to free the buffer on errors, as
  it isn't part of the chunkqueue yet).

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2976 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 19:10:36 +00:00
Stefan Bühler 6afad87d2e fix buffer, chunk and http_chunk API
* remove unused structs and functions
    (buffer_array, read_buffer)
  * change return type from int to void for many functions,
    as the return value (indicating error/success) was never checked,
    and the function would only fail on programming errors and not on
    invalid input; changed functions to use force_assert instead of
    returning an error.
  * all "len" parameters now are the real size of the memory to be read.
    the length of strings is given always without the terminating 0.
  * the "buffer" struct still counts the terminating 0 in ->used,
    provide buffer_string_length() to get the length of a string in a
    buffer.
    unset config "strings" have used == 0, which is used in some places
    to distinguish unset values from "" (empty string) values.
  * most buffer usages should now use it as string container.
  * optimise some buffer copying by "moving" data to other buffers
  * use (u)intmax_t for generic int-to-string functions
  * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET
  * converted BUFFER_APPEND_SLASH to inline function (no macro feature
    needed)
  * refactor: create chunkqueue_steal: moving (partial) chunks into another
    queue
  * http_chunk: added separate function to terminate chunked body instead of
    magic handling in http_chunk_append_mem().
    http_chunk_append_* now handle empty chunks, and never terminate the
    chunked body.

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 12:37:10 +00:00
Stefan Bühler d00e1e79b9 [connections] fix bug in connection state handling
if a request was finished (con->file_finished = 1) and the state
  machine was triggered, but the write queue was empty, it didn't
  actually finish the request.

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2973 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-07 13:32:54 +00:00
Stefan Bühler 9f2be4882d force assertion: setting FD_CLOEXEC must work (if available)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2952 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:29 +00:00
Stefan Bühler 07dd0bd0a5 add force_assert() to enforce assertions as simple assert()s are disabled by -DNDEBUG (fixes #2546)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2948 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:20 +00:00
Stefan Bühler 29a1070299 add comments for switch fall throughs
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2944 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-14 21:06:12 +00:00
Stefan Bühler 559b198f86 [auth] put REMOTE_USER into cgi environment, making it accessible to lua via lighty.req_env (fixes #2495)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2892 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-08-30 13:14:52 +00:00
Stefan Bühler 6d4d2118c3 [ssl] accept ssl renegotiations if they are not disabled (fixes #2491)
* don't fiddle with ssl internals
 * renegotiations should be safe with recent openssl versions,
   openssl itself should reject unsafe renegotiations

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2890 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-08-30 13:14:48 +00:00
Stefan Bühler 05858f6cf2 [ssl] Fix $HTTP["scheme"] conditional, could be "http" for ssl connections if the ssl $SERVER["socket"] conditional was nested (fixes #2501)
con->conf.is_ssl got removed and replaced by:
 * con->conf.ssl_enabled for the config var "ssl.engine" - it is only
   used to determine which server-sockets should use ssl. (usually not
   needed as it is mandatory and enough to set ssl.pemfile anyway)
 * con->srv_socket->is_ssl to detect the actual ssl status of the
   bound socket, which is the same as the ssl status of the connection
 * con->uri.scheme for the actual $HTTP["scheme"] value, also used for
   the CGI "HTTPS=ON" variable. This defaults to "https" if the
   connection uses ssl, but can be changed for example by mod_extforward
   if X-Forwarded-Proto: is set to either "http" or "https" (other values
   are ignored right now)

Also removed the broken srv_socket->is_proxy_ssl as it was a connection
value in a server_socket struct...

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2887 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-07-31 20:23:21 +00:00
Stefan Bühler 9b36534752 [core] return 501 Not Implemented in static file mode for all methods except GET/POST/HEAD/OPTIONS
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2882 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-06-29 10:53:22 +00:00
Stefan Bühler 25a2d665aa call ERR_clear_error only for ssl connections in CON_STATE_ERROR
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2867 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-03-25 17:22:34 +00:00
Stefan Bühler d4d1ff36aa add PATCH method (fixes #2424)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2852 152afb58-edef-0310-8abb-c4023f1b3aa9
2012-11-07 13:53:00 +00:00
Stefan Bühler db1d977dea Ignore EPIPE/ECONNRESET after SSL_shutdown (thx patdk-wk for reporting)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2849 152afb58-edef-0310-8abb-c4023f1b3aa9
2012-11-06 17:14:37 +00:00
Stefan Bühler d194c09da9 [ssl] fix segfault in counting renegotiations for openssl versions without TLSEXT/SNI
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2822 152afb58-edef-0310-8abb-c4023f1b3aa9
2011-12-23 10:31:57 +00:00
Stefan Bühler a94bdd07df [ssl] count renegotiations to prevent client renegotiations
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2808 152afb58-edef-0310-8abb-c4023f1b3aa9
2011-11-30 18:40:08 +00:00
Stefan Bühler 3518ab60ed Don't overwrite 401 (auth required) with 501 (unknown method) (fixes #2341)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2804 152afb58-edef-0310-8abb-c4023f1b3aa9
2011-09-05 09:32:43 +00:00
Stefan Bühler f434d514ad Limit amount of bytes we send in one go; fixes stalling in one connection and timeouts on slow systems.
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2801 152afb58-edef-0310-8abb-c4023f1b3aa9
2011-08-22 15:12:28 +00:00
Stefan Bühler cf719ec5b8 Silence annoying "connection closed: poll() -> ERR" error.log message (fixes #2257)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2771 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-09-17 16:43:11 +00:00
Stefan Bühler 7e5b0fe9ab Rename fdevent_event_add to _set to reflect what the function does. Fix some handlers.
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2765 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-08-17 09:54:42 +00:00
Stefan Bühler 38f2d1ddd7 cleanup fdevent code, removed linux-rtsig handler, replaced some fprintf calls
* use log functions
 * convert flags
 * fix handler callback prototype

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2752 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-08-06 21:57:15 +00:00
Stefan Bühler cf5fcf953d openssl: silence annoying error messages for errno==0 (fixes #2213)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2749 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-08-05 20:42:18 +00:00
Stefan Bühler bd4c4aaab2 Fix stalls while reading from ssl sockets (fixes #2197)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2729 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-07-04 07:45:13 +00:00
Stefan Bühler b3892c1410 Reset uri.authority before TLS servername handling, reset all "keep-alive" data in connection_del (fixes #2125)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2724 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-04-28 19:08:11 +00:00
Stefan Bühler 914e499723 Fix HUP detection in close-state if event-backend doesn't support FDEVENT_HUP (like select or poll on FreeBSD)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2712 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-02-04 10:13:37 +00:00
Stefan Bühler f601b8028b Append to previous buffer in con read (fixes #2147, found by liming, CVE-2010-0295)
* Remove ssl_error_want_reuse_buffer for SSL_read:
   Although the manual states we have to use the same arguments in the
   next call after SSL_ERROR_WANT_*, it has been running without this
   in 1.5 for a long time now.
 * As POST-data chunks get copied to the next queue, we reuse chunks
   there as well.

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2710 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-02-01 23:28:50 +00:00
Stefan Bühler 48fea28651 Fix request parser to handle packets with splitted \r\n\r\n (fixes #2105)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2696 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-11-29 14:13:13 +00:00
Stefan Bühler 2b79b9c3cb reset tlsext_server_name in connection_reset - fixes random hostnames in the $HTTP["host"] conditional
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2687 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-11-05 17:32:08 +00:00
Stefan Bühler ef28250d23 disable warning "CLOSE-read", part 2 (fixes #2091)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2685 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-27 08:46:05 +00:00
Stefan Bühler a81c2a1b02 disable warning "CLOSE-read"
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2684 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-26 19:30:40 +00:00
Peter Colberg 8b6dae4139 Add TLS servername indication (SNI) support (fixes #386, thx Peter Colberg <peter@colberg.org>)
* This patch may "break" some configs, if they do stupid things. Like setting
  ssl.pemfile to a not existing file in a "non-socket/non-ssl" block.
  Fix them! :)

From: Peter Colberg <peter@colberg.org>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2648 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-14 13:39:59 +00:00
Stefan Bühler 20c4cd55c3 Fix close_timeout_ts trigger (should finally fix lingering close)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2645 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-12 20:59:38 +00:00
Stefan Bühler 7c65bd74ff commit 476c5d48ea9fbd4d1c6d4ef3f128b6e4898a297f
Fix linger-on-close behaviour to avoid rare failure conditions.

     - Don't assume that when FIONREAD returns 0, that it's safe to close the
       socket.  There may still be data that's about to arrive, and we'll still
       send an RST if the socket is confused, potentially confusing the client.

     - Don't close the connection immediately after sending a successful
       response; linger-on-close was only happening in the case of errors, but it
       has to happen in case of success too, because the client doesn't
       necessarily know we're about to close after this request, and may have
       sent additional ones. (eg. if server.max-keep-alive-requests is small.)

     - Don't close the connection immediately even if keep_alive is 0; there are
       several reasons keep_alive can be 0.  If the client requested Connection:
       close, then it would be okay to close right away, since we can assume he
       didn't send anything else.  But it's harmless (and more resilient) to do
       the lingering regardless.

     - Increase the lingering timeout from 1s to 30s.  In the vast majority of
       cases, the timeout never kicks in anyway.  The only times when it might
       be needed are a) in race conditions, in which case timing out too early
       defeats the purpose of lingering at all; b) if there's a lot of data,
       which is basically the same as (a); or c) if the remote end disappears,
       in which case we now suffer through a longer timeout... but we would
       anyway, if we were waiting for them to receive our transmission.

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2636 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-11 20:32:33 +00:00
Stefan Bühler 22e8b456a9 Fix header inclusion order, always include "config.h" before any system header
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2624 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-11 14:31:42 +00:00
Stefan Bühler 4df22f2a32 Fix issues found with clang analyzer
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2594 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-07-21 20:35:27 +00:00