Polish redbean APIs and docs (#446)

* Remove undocumented ProgramSslCompression
* Rename GetLastModified to GetAssetLastModified
* Rename IsCompressed to IsAssetCompressed
* Reorganize currently deprecated functions
* Update sockopt documentation for clarity
This commit is contained in:
Paul Kulchenko 2022-06-23 18:54:35 -07:00 committed by GitHub
parent a9d77362f9
commit 1bce1ca2e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 66 deletions

View file

@ -317,7 +317,7 @@ local function main()
if not IsAcceptablePath(paths[i]) then if not IsAcceptablePath(paths[i]) then
Write(' <small>[BLOCKED]</small>') Write(' <small>[BLOCKED]</small>')
end end
if not IsCompressed(paths[i]) then if not IsAssetCompressed(paths[i]) then
Write(' <small>[UNCOMPRESSED]</small>') Write(' <small>[UNCOMPRESSED]</small>')
end end
if (GetAssetMode(paths[i]) & 0xF000) == 0x4000 then if (GetAssetMode(paths[i]) & 0xF000) == 0x4000 then
@ -325,7 +325,7 @@ local function main()
end end
Write('<br>\r\n') Write('<br>\r\n')
Write('Modified: ') Write('Modified: ')
Write(FormatHttpDateTime(GetLastModifiedTime(paths[i]))) Write(FormatHttpDateTime(GetAssetLastModifiedTime(paths[i])))
Write('<br>\r\n') Write('<br>\r\n')
Write('Mode: ') Write('Mode: ')
Write("0%o" % {GetAssetMode(paths[i])}) Write("0%o" % {GetAssetMode(paths[i])})

View file

@ -725,6 +725,11 @@ FUNCTIONS
EscapeUser(str) → str EscapeUser(str) → str
Escapes URL username. See kescapeauthority.c. Escapes URL username. See kescapeauthority.c.
EvadeDragnetSurveillance(bool)
If this option is programmed then redbean will not transmit a
Server Name Indicator (SNI) when performing Fetch() requests.
This function is not available in unsecure mode.
Fetch(url:str[,body:str|{method=value:str,body=value:str,headers=table,...}]) Fetch(url:str[,body:str|{method=value:str,body=value:str,headers=table,...}])
→ status:int,{header:str=value:str,...},body:str → status:int,{header:str=value:str,...},body:str
Sends an HTTP/HTTPS request to the specified URL. If only the URL is Sends an HTTP/HTTPS request to the specified URL. If only the URL is
@ -761,15 +766,24 @@ FUNCTIONS
GetAssetComment(path:str) → str GetAssetComment(path:str) → str
Returns comment text associated with asset in the ZIP central Returns comment text associated with asset in the ZIP central
directory. Also available as GetComment (deprecated). directory.
Also available as GetComment (deprecated).
GetAssetLastModifiedTime(path:str) → seconds:number
Returns UNIX timestamp for modification time of a ZIP asset (or
local file if the -D flag is used).
If both a file and a ZIP asset are present, then the file is used.
Also available as GetLastModifiedTime (deprecated).
GetAssetMode(path:str) → int GetAssetMode(path:str) → int
Returns UNIX-style octal mode for ZIP asset (or local file if the Returns UNIX-style octal mode for ZIP asset (or local file if the
-D flag is used) -D flag is used).
If both a file and a ZIP asset are present, then the file is used.
GetAssetSize(path:str) → int GetAssetSize(path:str) → int
Returns byte size of uncompressed contents of ZIP asset (or local Returns byte size of uncompressed contents of ZIP asset (or local
file if the -D flag is used) file if the -D flag is used).
If both a file and a ZIP asset are present, then the file is used.
GetBody() → str GetBody() → str
Returns the request message body if present or an empty string. Returns the request message body if present or an empty string.
@ -927,8 +941,8 @@ FUNCTIONS
GetHttpVersion() → int GetHttpVersion() → int
Returns the request HTTP protocol version, which can be 9 for Returns the request HTTP protocol version, which can be 9 for
HTTP/0.9, 10 for HTTP/1.0, or 11 for HTTP/1.1. Also available HTTP/0.9, 10 for HTTP/1.0, or 11 for HTTP/1.1.
as GetVersion (deprecated). Also available as GetVersion (deprecated).
GetRandomBytes([length:int]) → str GetRandomBytes([length:int]) → str
Returns string with the specified number of random bytes (1..256). Returns string with the specified number of random bytes (1..256).
@ -965,9 +979,10 @@ FUNCTIONS
Returns true if IP address is part of the localhost network Returns true if IP address is part of the localhost network
(127.0.0.0/8). (127.0.0.0/8).
IsCompressed(path:str) → bool IsAssetCompressed(path:str) → bool
Returns true if ZIP artifact at path is stored on disk using Returns true if ZIP artifact at path is stored on disk using
DEFLATE compression. DEFLATE compression.
Also available as IsCompressed (deprecated).
IndentLines(str[,int]) → str IndentLines(str[,int]) → str
Adds spaces to beginnings of multiline string. If the int Adds spaces to beginnings of multiline string. If the int
@ -1122,11 +1137,6 @@ FUNCTIONS
handshake performance 10x and eliminates a network round trip. handshake performance 10x and eliminates a network round trip.
This function is not available in unsecure mode. This function is not available in unsecure mode.
EvadeDragnetSurveillance(bool)
If this option is programmed then redbean will not transmit a
Server Name Indicator (SNI) when performing Fetch() requests.
This function is not available in unsecure mode.
ProgramSslPresharedKey(key:str,identity:str) ProgramSslPresharedKey(key:str,identity:str)
This function can be used to enable the PSK ciphersuites which This function can be used to enable the PSK ciphersuites which
simplify SSL and enhance its performance in controlled simplify SSL and enhance its performance in controlled
@ -2667,8 +2677,8 @@ UNIX MODULE
Tunes networking parameters. Tunes networking parameters.
`level` and `optname` may be one of the following. The ellipses type `level` and `optname` may be one of the following pairs. The ellipses
signature above changes depending on which options are used. type signature above changes depending on which options are used.
unix.getsockopt(fd:int, level:int, optname:int) unix.getsockopt(fd:int, level:int, optname:int)
├─→ value:int ├─→ value:int
@ -2677,20 +2687,20 @@ UNIX MODULE
├─→ true ├─→ true
└─→ nil, unix.Errno └─→ nil, unix.Errno
- `SOL_SOCKET` + `SO_TYPE` - `SOL_SOCKET`, `SO_TYPE`
- `SOL_SOCKET` + `SO_DEBUG` - `SOL_SOCKET`, `SO_DEBUG`
- `SOL_SOCKET` + `SO_ACCEPTCONN` - `SOL_SOCKET`, `SO_ACCEPTCONN`
- `SOL_SOCKET` + `SO_BROADCAST` - `SOL_SOCKET`, `SO_BROADCAST`
- `SOL_SOCKET` + `SO_REUSEADDR` - `SOL_SOCKET`, `SO_REUSEADDR`
- `SOL_SOCKET` + `SO_REUSEPORT` - `SOL_SOCKET`, `SO_REUSEPORT`
- `SOL_SOCKET` + `SO_KEEPALIVE` - `SOL_SOCKET`, `SO_KEEPALIVE`
- `SOL_SOCKET` + `SO_DONTROUTE` - `SOL_SOCKET`, `SO_DONTROUTE`
- `SOL_TCP` + `TCP_NODELAY` - `SOL_TCP`, `TCP_NODELAY`
- `SOL_TCP` + `TCP_CORK` - `SOL_TCP`, `TCP_CORK`
- `SOL_TCP` + `TCP_QUICKACK` - `SOL_TCP`, `TCP_QUICKACK`
- `SOL_TCP` + `TCP_FASTOPEN_CONNECT` - `SOL_TCP`, `TCP_FASTOPEN_CONNECT`
- `SOL_TCP` + `TCP_DEFER_ACCEPT` - `SOL_TCP`, `TCP_DEFER_ACCEPT`
- `SOL_IP` + `IP_HDRINCL` - `SOL_IP`, `IP_HDRINCL`
unix.getsockopt(fd:int, level:int, optname:int) unix.getsockopt(fd:int, level:int, optname:int)
├─→ value:int ├─→ value:int
@ -2699,21 +2709,21 @@ UNIX MODULE
├─→ true ├─→ true
└─→ nil, unix.Errno └─→ nil, unix.Errno
- `SOL_SOCKET` + `SO_SNDBUF` - `SOL_SOCKET`, `SO_SNDBUF`
- `SOL_SOCKET` + `SO_RCVBUF` - `SOL_SOCKET`, `SO_RCVBUF`
- `SOL_SOCKET` + `SO_RCVLOWAT` - `SOL_SOCKET`, `SO_RCVLOWAT`
- `SOL_SOCKET` + `SO_SNDLOWAT` - `SOL_SOCKET`, `SO_SNDLOWAT`
- `SOL_TCP` + `TCP_KEEPIDLE` - `SOL_TCP`, `TCP_KEEPIDLE`
- `SOL_TCP` + `TCP_KEEPINTVL` - `SOL_TCP`, `TCP_KEEPINTVL`
- `SOL_TCP` + `TCP_FASTOPEN` - `SOL_TCP`, `TCP_FASTOPEN`
- `SOL_TCP` + `TCP_KEEPCNT` - `SOL_TCP`, `TCP_KEEPCNT`
- `SOL_TCP` + `TCP_MAXSEG` - `SOL_TCP`, `TCP_MAXSEG`
- `SOL_TCP` + `TCP_SYNCNT` - `SOL_TCP`, `TCP_SYNCNT`
- `SOL_TCP` + `TCP_NOTSENT_LOWAT` - `SOL_TCP`, `TCP_NOTSENT_LOWAT`
- `SOL_TCP` + `TCP_WINDOW_CLAMP` - `SOL_TCP`, `TCP_WINDOW_CLAMP`
- `SOL_IP` + `IP_TOS` - `SOL_IP`, `IP_TOS`
- `SOL_IP` + `IP_MTU` - `SOL_IP`, `IP_MTU`
- `SOL_IP` + `IP_TTL` - `SOL_IP`, `IP_TTL`
unix.getsockopt(fd:int, level:int, optname:int) unix.getsockopt(fd:int, level:int, optname:int)
├─→ secs:int, nsecs:int ├─→ secs:int, nsecs:int
@ -2722,14 +2732,14 @@ UNIX MODULE
├─→ true ├─→ true
└─→ nil, unix.Errno └─→ nil, unix.Errno
- `SOL_SOCKET` + `SO_RCVTIMEO`: If this option is specified then - `SOL_SOCKET`, `SO_RCVTIMEO`: If this option is specified then
your stream socket will have a read() / recv() timeout. If the your stream socket will have a read() / recv() timeout. If the
specified interval elapses without receiving data, then EAGAIN specified interval elapses without receiving data, then EAGAIN
shall be returned by read. If this option is used on listening shall be returned by read. If this option is used on listening
sockets, it'll be inherited by accepted sockets. Your redbean sockets, it'll be inherited by accepted sockets. Your redbean
already does this for GetClientFd() based on the `-t` flag. already does this for GetClientFd() based on the `-t` flag.
- `SOL_SOCKET` + `SO_SNDTIMEO`: This is the same as `SO_RCVTIMEO` - `SOL_SOCKET`, `SO_SNDTIMEO`: This is the same as `SO_RCVTIMEO`
but it applies to the write() / send() functions. but it applies to the write() / send() functions.
unix.getsockopt(fd:int, unix.SOL_SOCKET, unix.SO_LINGER) unix.getsockopt(fd:int, unix.SOL_SOCKET, unix.SO_LINGER)

View file

@ -4796,17 +4796,6 @@ static int LuaEvadeDragnetSurveillance(lua_State *L) {
return LuaProgramBool(L, &evadedragnetsurveillance); return LuaProgramBool(L, &evadedragnetsurveillance);
} }
static int LuaProgramSslCompression(lua_State *L) {
#ifndef UNSECURE
if (!unsecure) {
OnlyCallFromInitLua(L, "ProgramSslCompression");
conf.disable_compression = confcli.disable_compression =
!lua_toboolean(L, 1);
}
#endif
return 0;
}
static int LuaHidePath(lua_State *L) { static int LuaHidePath(lua_State *L) {
size_t pathlen; size_t pathlen;
const char *path; const char *path;
@ -4857,7 +4846,7 @@ static int LuaGetAssetMode(lua_State *L) {
return 1; return 1;
} }
static int LuaGetLastModifiedTime(lua_State *L) { static int LuaGetAssetLastModifiedTime(lua_State *L) {
size_t pathlen; size_t pathlen;
struct Asset *a; struct Asset *a;
const char *path; const char *path;
@ -4895,7 +4884,7 @@ static int LuaGetAssetSize(lua_State *L) {
return 1; return 1;
} }
static int LuaIsCompressed(lua_State *L) { static int LuaIsAssetCompressed(lua_State *L) {
size_t pathlen; size_t pathlen;
struct Asset *a; struct Asset *a;
const char *path; const char *path;
@ -4964,6 +4953,7 @@ static const char *const kDontAutoComplete[] = {
"GetBody", // "GetBody", //
"GetClientAddr", // "GetClientAddr", //
"GetClientFd", // "GetClientFd", //
"GetComment", // deprecated
"GetCookie", // "GetCookie", //
"GetEffectivePath", // "GetEffectivePath", //
"GetFragment", // "GetFragment", //
@ -4971,11 +4961,13 @@ static const char *const kDontAutoComplete[] = {
"GetHeaders", // "GetHeaders", //
"GetHost", // "GetHost", //
"GetHttpVersion", // "GetHttpVersion", //
"GetLastModifiedTime", // deprecated
"GetMethod", // "GetMethod", //
"GetParam", // "GetParam", //
"GetParams", // "GetParams", //
"GetPass", // "GetPass", //
"GetPath", // "GetPath", //
"GetPayload", // deprecated
"GetPort", // "GetPort", //
"GetRemoteAddr", // "GetRemoteAddr", //
"GetScheme", // "GetScheme", //
@ -4984,8 +4976,10 @@ static const char *const kDontAutoComplete[] = {
"GetStatus", // "GetStatus", //
"GetUrl", // "GetUrl", //
"GetUser", // "GetUser", //
"GetVersion", // deprecated
"HasParam", // "HasParam", //
"IsClientUsingSsl", // "IsClientUsingSsl", //
"IsCompressed", // deprecated
"LaunchBrowser", // "LaunchBrowser", //
"LuaProgramSslRequired", // TODO "LuaProgramSslRequired", // TODO
"ProgramAddr", // TODO "ProgramAddr", // TODO
@ -4999,7 +4993,6 @@ static const char *const kDontAutoComplete[] = {
"ProgramPrivateKey", // TODO "ProgramPrivateKey", // TODO
"ProgramSslCiphersuite", // TODO "ProgramSslCiphersuite", // TODO
"ProgramSslClientVerify", // TODO "ProgramSslClientVerify", // TODO
"ProgramSslCompression", //
"ProgramSslTicketLifetime", // "ProgramSslTicketLifetime", //
"ProgramTimeout", // TODO "ProgramTimeout", // TODO
"ProgramUid", // "ProgramUid", //
@ -5050,12 +5043,12 @@ static const luaL_Reg kLuaFuncs[] = {
{"FormatHttpDateTime", LuaFormatHttpDateTime}, // {"FormatHttpDateTime", LuaFormatHttpDateTime}, //
{"FormatIp", LuaFormatIp}, // {"FormatIp", LuaFormatIp}, //
{"GetAssetComment", LuaGetAssetComment}, // {"GetAssetComment", LuaGetAssetComment}, //
{"GetAssetLastModifiedTime", LuaGetAssetLastModifiedTime}, //
{"GetAssetMode", LuaGetAssetMode}, // {"GetAssetMode", LuaGetAssetMode}, //
{"GetAssetSize", LuaGetAssetSize}, // {"GetAssetSize", LuaGetAssetSize}, //
{"GetBody", LuaGetBody}, // {"GetBody", LuaGetBody}, //
{"GetClientAddr", LuaGetClientAddr}, // {"GetClientAddr", LuaGetClientAddr}, //
{"GetClientFd", LuaGetClientFd}, // {"GetClientFd", LuaGetClientFd}, //
{"GetComment", LuaGetAssetComment}, //
{"GetCookie", LuaGetCookie}, // {"GetCookie", LuaGetCookie}, //
{"GetCpuCore", LuaGetCpuCore}, // {"GetCpuCore", LuaGetCpuCore}, //
{"GetCpuCount", LuaGetCpuCount}, // {"GetCpuCount", LuaGetCpuCount}, //
@ -5070,7 +5063,6 @@ static const luaL_Reg kLuaFuncs[] = {
{"GetHostOs", LuaGetHostOs}, // {"GetHostOs", LuaGetHostOs}, //
{"GetHttpReason", LuaGetHttpReason}, // {"GetHttpReason", LuaGetHttpReason}, //
{"GetHttpVersion", LuaGetHttpVersion}, // {"GetHttpVersion", LuaGetHttpVersion}, //
{"GetLastModifiedTime", LuaGetLastModifiedTime}, //
{"GetLogLevel", LuaGetLogLevel}, // {"GetLogLevel", LuaGetLogLevel}, //
{"GetMethod", LuaGetMethod}, // {"GetMethod", LuaGetMethod}, //
{"GetMonospaceWidth", LuaGetMonospaceWidth}, // {"GetMonospaceWidth", LuaGetMonospaceWidth}, //
@ -5078,7 +5070,6 @@ static const luaL_Reg kLuaFuncs[] = {
{"GetParams", LuaGetParams}, // {"GetParams", LuaGetParams}, //
{"GetPass", LuaGetPass}, // {"GetPass", LuaGetPass}, //
{"GetPath", LuaGetPath}, // {"GetPath", LuaGetPath}, //
{"GetPayload", LuaGetBody}, //
{"GetPort", LuaGetPort}, // {"GetPort", LuaGetPort}, //
{"GetRandomBytes", LuaGetRandomBytes}, // {"GetRandomBytes", LuaGetRandomBytes}, //
{"GetRedbeanVersion", LuaGetRedbeanVersion}, // {"GetRedbeanVersion", LuaGetRedbeanVersion}, //
@ -5089,7 +5080,6 @@ static const luaL_Reg kLuaFuncs[] = {
{"GetTime", LuaGetTime}, // {"GetTime", LuaGetTime}, //
{"GetUrl", LuaGetUrl}, // {"GetUrl", LuaGetUrl}, //
{"GetUser", LuaGetUser}, // {"GetUser", LuaGetUser}, //
{"GetVersion", LuaGetHttpVersion}, //
{"GetZipPaths", LuaGetZipPaths}, // {"GetZipPaths", LuaGetZipPaths}, //
{"HasControlCodes", LuaHasControlCodes}, // {"HasControlCodes", LuaHasControlCodes}, //
{"HasParam", LuaHasParam}, // {"HasParam", LuaHasParam}, //
@ -5099,7 +5089,7 @@ static const luaL_Reg kLuaFuncs[] = {
{"IsAcceptablePath", LuaIsAcceptablePath}, // {"IsAcceptablePath", LuaIsAcceptablePath}, //
{"IsAcceptablePort", LuaIsAcceptablePort}, // {"IsAcceptablePort", LuaIsAcceptablePort}, //
{"IsClientUsingSsl", LuaIsClientUsingSsl}, // {"IsClientUsingSsl", LuaIsClientUsingSsl}, //
{"IsCompressed", LuaIsCompressed}, // {"IsAssetCompressed", LuaIsAssetCompressed}, //
{"IsDaemon", LuaIsDaemon}, // {"IsDaemon", LuaIsDaemon}, //
{"IsHeaderRepeatable", LuaIsHeaderRepeatable}, // {"IsHeaderRepeatable", LuaIsHeaderRepeatable}, //
{"IsHiddenPath", LuaIsHiddenPath}, // {"IsHiddenPath", LuaIsHiddenPath}, //
@ -5176,13 +5166,18 @@ static const luaL_Reg kLuaFuncs[] = {
{"ProgramPrivateKey", LuaProgramPrivateKey}, // {"ProgramPrivateKey", LuaProgramPrivateKey}, //
{"ProgramSslCiphersuite", LuaProgramSslCiphersuite}, // {"ProgramSslCiphersuite", LuaProgramSslCiphersuite}, //
{"ProgramSslClientVerify", LuaProgramSslClientVerify}, // {"ProgramSslClientVerify", LuaProgramSslClientVerify}, //
{"ProgramSslCompression", LuaProgramSslCompression}, //
{"ProgramSslFetchVerify", LuaProgramSslFetchVerify}, // {"ProgramSslFetchVerify", LuaProgramSslFetchVerify}, //
{"ProgramSslInit", LuaProgramSslInit}, // {"ProgramSslInit", LuaProgramSslInit}, //
{"ProgramSslPresharedKey", LuaProgramSslPresharedKey}, // {"ProgramSslPresharedKey", LuaProgramSslPresharedKey}, //
{"ProgramSslRequired", LuaProgramSslRequired}, // {"ProgramSslRequired", LuaProgramSslRequired}, //
{"ProgramSslTicketLifetime", LuaProgramSslTicketLifetime}, // {"ProgramSslTicketLifetime", LuaProgramSslTicketLifetime}, //
#endif #endif
// deprecated
{"GetPayload", LuaGetBody}, //
{"GetComment", LuaGetAssetComment}, //
{"GetVersion", LuaGetHttpVersion}, //
{"IsCompressed", LuaIsAssetCompressed}, //
{"GetLastModifiedTime", LuaGetAssetLastModifiedTime}, //
}; };
static const luaL_Reg kLuaLibs[] = { static const luaL_Reg kLuaLibs[] = {