Have redbean show zip listing as default / handler

If an "index.lua" or "index.html" doesn't exist in zip file or the
filesystem, and no redirects have been defined for it either, then
redbean will render a listing of the zip central directory content
only if the request uri points to the root path.
This commit is contained in:
Justine Tunney 2021-03-29 01:22:49 -07:00
parent ae300d0c40
commit 1753b669cf
10 changed files with 436 additions and 112 deletions

View file

@ -29,23 +29,21 @@
* @see xasprintf() for a better API
*/
int(vasprintf)(char **strp, const char *fmt, va_list va) {
/*
* This implementation guarantees the smallest possible allocation,
* using an optimistic approach w/o changing asymptotic complexity.
*/
size_t size = 32;
if ((*strp = malloc(size))) {
va_list va2;
int wrote;
char *p;
size_t size;
va_list va2;
if ((*strp = malloc((size = 512)))) {
va_copy(va2, va);
int wrote = (vsnprintf)(*strp, size, fmt, va);
wrote = (vsnprintf)(*strp, size, fmt, va);
if (wrote == -1) return -1;
if (wrote <= size - 1) {
if (wrote < size) {
if ((p = realloc(*strp, wrote + 1))) *strp = p;
return wrote;
} else {
size = wrote + 1;
char *buf2 = realloc(*strp, size);
if (buf2) {
*strp = buf2;
if ((p = realloc(*strp, size))) {
*strp = p;
wrote = (vsnprintf)(*strp, size, fmt, va2);
assert(wrote == size - 1);
return wrote;

View file

@ -22,15 +22,29 @@
#include "libc/sysv/consts/sock.h"
int sys_socket(int family, int type, int protocol) {
int rc, olderr, modernflags;
olderr = errno;
rc = __sys_socket(family, type, protocol);
if ((SupportsLinux() || SupportsXnu()) &&
(rc == -1 && errno == EINVAL /* rhel5 behavior */) &&
(modernflags = (type & (SOCK_CLOEXEC | SOCK_NONBLOCK)))) {
errno = olderr;
rc = __fixupnewsockfd(__sys_socket(family, type & ~modernflags, protocol),
modernflags);
static bool once, demodernize;
int sock, olderr;
if (!once && (type & (SOCK_CLOEXEC | SOCK_NONBLOCK))) {
if (IsXnu()) {
demodernize = true;
once = true;
} else {
olderr = errno;
if ((sock = __sys_socket(family, type, protocol)) != -1) {
once = true;
return sock;
} else {
errno = olderr;
demodernize = true;
once = true;
}
}
}
if (!demodernize) {
return __sys_socket(family, type, protocol);
} else {
return __fixupnewsockfd(
__sys_socket(family, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), protocol),
type);
}
return rc;
}