(thx pegasus)
disable CGI stdin input optimizations if CGI might Upgrade connection,
since if we upgrade protocols, the original Content-Length -- expected
to be 0 for Upgrade -- does not represent the end of the input.
reduce trace on Upgrade'd backend connection when ECONNRESET received,
which, for example, apparently might occur if a backend calls close()
on socket without first calling shutdown(fd, SHUT_WR) -- seen on Linux
kernel 5.16.15 where lighttpd received ECONNRESET when trying to read()
(instead of receiving EOF).
ensure socket ready for writing before checking connect() status
(sanity check in case request gets rescheduled for another reason
before the socket is ready for writing)
connect to backend (mod_cgi, mod_proxy, mod_sockproxy, mod_wstunnel)
for streaming request body without waiting for initial data in request
body. Useful for things like websockets when data starts on server-side
Add support for WebSockets over HTTP/2 to lighttpd core and to
mod_cgi w/ config: cgi.upgrade = "enable"
mod_proxy w/ config: proxy.header += ("upgrade" => "enable")
mod_wstunnel
HTTP/2 CONNECT extension defined in RFC8441 is translated to HTTP/1.1
'Upgrade: websocket' requests to mod_cgi or mod_proxy, and is handled
directly in mod_wstunnel.
x-ref:
WebSockets over HTTP/2
https://redmine.lighttpd.net/issues/3151
Bootstrapping WebSockets with HTTP/2
https://datatracker.ietf.org/doc/html/rfc8441
allow removal of lighty.r.req_env[] element by assigning nil value
(blank values ("") are permitted for environment variables,
unlike request and response headers)
(thx Lars Bingchong)
empty env var must be set to blank string and not left unset
(regression in lighttpd 1.4.56 - lighttpd 1.4.64)
x-ref:
https://stackoverflow.com/a/52913064/1338888
append to X-Forwarded-For
overwrite X-Host, X-Forwarded-Host, X-Forwarded-Proto
(with value that might be obtained from trusted downstream proxy
configured with mod_extforward)
(do not blindly pass through client-provided values, unless
mod_extforward has been configured to trust the downstream proxy)
(RFC 7239 Forwarded is a standardized header with structured format
and ought to be preferred over the legacy X-* headers, where available)
lighty.c.header_tokens convenience func to create a sequence table
of tokens parsed from a given string, e.g. an HTTP header. The purpose
of this routine is to made it easier to properly parse an HTTP header
into tokens since token separators can be part of quoted-strings, and
they are not token separators when part of quoted strings.
The sequence table t returned from lighty.c.header_tokens() can be
walked with:
for i = 1, #t do
-- <body here>
end
While walking, each element can be passed to lighty.c.quoteddec()
to decode, as non-quoted-string elements are returned as-is.
Note: lighty.c.header_tokens() returns a sequence table,
which is different from lighty.c.cookie_tokens(),
which returns a key/value table of cookies.
(thx dirk4000)
Storing the config list into a data structure with case-insensitive keys
meant that if the config list contained multiple entries which differed
in case-only, then only one entry would survive. Case-sensitivity of
username matters for HTTP Digest auth. Store config list in value list.
x-ref:
"mod_auth (configuration): Change of behavior in user name handling"
https://redmine.lighttpd.net/boards/2/topics/10275
fix header,content legacy table clear/reset
(regression since lighttpd 1.4.60)
(newer mod_magnet interfaces in lighttpd 1.4.60 should be preferred
over legacy lighty.header and lighty.content tables)
Lua does not provide an easy way to (always) get num table elements.
lua_rawlen() is usable only on tables created as a sequence table;
lua_rawlen() might return any lua table "edge", including 0, for other
tables, even if those tables contain entries. lua_next() must be used
to walk lua tables.
lighty.c.quotedenc() and lighty.c.quoteddec() convenience functions
to encode and decode MIME quoted-string, e.g. quoted-string formats
in HTTP headers.
Prefer r->tmp_buf with lua 5.3+ where r->tmp_buf is quick to access.
Otherwise use chunk_buffer_acquire()/chunk_buffer_release(), which
is also quick, but may be slightly slower.
If an HTTP/1.1 request is configured to force an HTTP/1.0 response
(server.protocol-http11 = "disable"), then also disable keep-alive
(which is enabled by default in HTTP/1.1). This overrides the
request header Connection: keep-alive (not re-validated), which is
unlikely to be sent with an HTTP/1.1 request.
reset after error raised attaching content
(The lua stack has been unwound after the exception)
(Might avoid reloading script if an alt env is used; not tested)