mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 22:38:30 +00:00
Add root redirect for redbean webserver
We have a webserver demo: make -j8 o//tool/net/redbean.com o/tool/net/redbean.com -v It's been a little bit confusing that until now you had to visit the following URL in order to see the default web page: http://127.0.0.1:8080/tool/net/redbean.html The following URLs will now redirect to the above page, but only if nothing's been defined for those paths and they would otherwise result in a 404 response: http://127.0.0.1:8080/ http://127.0.0.1:8080/index.html
This commit is contained in:
parent
40291c9db3
commit
91f4167a45
1 changed files with 5 additions and 2 deletions
|
@ -846,7 +846,7 @@ static char *AppendContentEncodingGzip(char *p) {
|
||||||
static char *AppendRedirect(char *p, const char *s) {
|
static char *AppendRedirect(char *p, const char *s) {
|
||||||
VERBOSEF("%s %s %.*s redirect %s", clientaddrstr, kHttpMethod[req.method],
|
VERBOSEF("%s %s %.*s redirect %s", clientaddrstr, kHttpMethod[req.method],
|
||||||
req.uri.b - req.uri.a, inbuf + req.uri.a, s);
|
req.uri.b - req.uri.a, inbuf + req.uri.a, s);
|
||||||
p = AppendStatus(p, 302, "Temporary Redirect");
|
p = AppendStatus(p, 307, "Temporary Redirect");
|
||||||
p = AppendHeaderName(p, "Location");
|
p = AppendHeaderName(p, "Location");
|
||||||
p = STPCPY(p, s);
|
p = STPCPY(p, s);
|
||||||
return AppendCrlf(p);
|
return AppendCrlf(p);
|
||||||
|
@ -942,7 +942,7 @@ void HandleRequest(size_t got) {
|
||||||
req.headers[kHttpReferer].b - req.headers[kHttpReferer].a,
|
req.headers[kHttpReferer].b - req.headers[kHttpReferer].a,
|
||||||
inbuf + req.headers[kHttpReferer].a);
|
inbuf + req.headers[kHttpReferer].a);
|
||||||
if ((location = LookupRedirect(path, pathlen))) {
|
if ((location = LookupRedirect(path, pathlen))) {
|
||||||
p = AppendRedirect(p, DEFAULT_PATH);
|
p = AppendRedirect(p, location);
|
||||||
} else if ((a = FindFile(path, pathlen))) {
|
} else if ((a = FindFile(path, pathlen))) {
|
||||||
if (IsNotModified(a)) {
|
if (IsNotModified(a)) {
|
||||||
VERBOSEF("%s %s %.*s not modified", clientaddrstr,
|
VERBOSEF("%s %s %.*s not modified", clientaddrstr,
|
||||||
|
@ -1012,6 +1012,9 @@ void HandleRequest(size_t got) {
|
||||||
} else {
|
} else {
|
||||||
p = AppendVaryContentEncoding(p);
|
p = AppendVaryContentEncoding(p);
|
||||||
}
|
}
|
||||||
|
} else if (!strncmp(path, "/", pathlen) ||
|
||||||
|
!strncmp(path, "/index.html", pathlen)) {
|
||||||
|
p = AppendRedirect(p, DEFAULT_PATH);
|
||||||
} else {
|
} else {
|
||||||
WARNF("%s %s %.*s not found", clientaddrstr, kHttpMethod[req.method],
|
WARNF("%s %s %.*s not found", clientaddrstr, kHttpMethod[req.method],
|
||||||
pathlen, path);
|
pathlen, path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue