mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
f7ff77d865
- Invent iso8601us() for faster timestamps - Improve --strace descriptions of sigset_t - Rebuild the Landlock Make bootstrap binary - Introduce MODE=sysv for non-Windows builds - Permit OFD fcntl() locks under pledge(flock) - redbean can now protect your kernel from ddos - Have vfork() fallback to sys_fork() not fork() - Change kmalloc() to not die when out of memory - Improve documentation for some termios functions - Rewrite putenv() and friends to conform to POSIX - Fix linenoise + strace verbosity issue on Windows - Fix regressions in our ability to show backtraces - Change redbean SetHeader() to no-op if value is nil - Improve fcntl() so SQLite locks work in non-WAL mode - Remove some unnecessary work during fork() on Windows - Create redbean-based SSL reverse proxy for IPv4 TurfWar - Fix ape/apeinstall.sh warning when using non-bash shells - Add ProgramTrustedIp(), and IsTrustedIp() APIs to redbean - Support $PWD, $UID, $GID, and $EUID in command interpreter - Introduce experimental JTqFpD APE prefix for non-Windows builds - Invent blackhole daemon for firewalling IP addresses via UNIX named socket - Add ProgramTokenBucket(), AcquireToken(), and CountTokens() APIs to redbean
46 lines
1.4 KiB
Lua
46 lines
1.4 KiB
Lua
-- reverse proxy for turfwar
|
|
|
|
ProgramPort(443)
|
|
ProgramTokenBucket()
|
|
|
|
RELAY_HEADERS_TO_CLIENT = {
|
|
'Access-Control-Allow-Origin',
|
|
'Cache-Control',
|
|
'Connection',
|
|
'Content-Encoding',
|
|
'Content-Type',
|
|
'Last-Modified',
|
|
'Referrer-Policy',
|
|
'Vary',
|
|
}
|
|
|
|
function OnWorkerStart()
|
|
assert(unix.unveil(nil, nil))
|
|
assert(unix.pledge("stdio inet", nil, unix.PLEDGE_PENALTY_RETURN_EPERM))
|
|
end
|
|
|
|
function OnHttpRequest()
|
|
local status, headers, body =
|
|
Fetch('http://127.0.0.1' .. EscapePath(GetPath()),
|
|
{method = GetMethod(),
|
|
headers = {
|
|
['Accept'] = GetHeader('Accept'),
|
|
['Accept-Encoding'] = GetHeader('Accept-Encoding'),
|
|
['CF-IPCountry'] = GetHeader('CF-IPCountry'),
|
|
['If-Modified-Since'] = GetHeader('If-Modified-Since'),
|
|
['Referer'] = GetHeader('Referer'),
|
|
['Sec-CH-UA-Platform'] = GetHeader('Sec-CH-UA-Platform'),
|
|
['User-Agent'] = GetHeader('User-Agent'),
|
|
['X-Forwarded-For'] = FormatIp(GetClientAddr())}})
|
|
if status then
|
|
SetStatus(status)
|
|
for k,v in pairs(RELAY_HEADERS_TO_CLIENT) do
|
|
SetHeader(v, headers[v])
|
|
end
|
|
Write(body)
|
|
else
|
|
err = headers
|
|
Log(kLogError, "proxy failed %s" % {err})
|
|
ServeError(503)
|
|
end
|
|
end
|