mirror of
https://github.com/1f349/violet.git
synced 2024-11-21 19:01:39 +00:00
Minor changes to error page loading code
This commit is contained in:
parent
61097981d6
commit
71f8aaaf16
@ -6,6 +6,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,8 +84,21 @@ func (e *ErrorPages) internalCompile(m map[int]func(rw http.ResponseWriter)) err
|
|||||||
// get file name and extension
|
// get file name and extension
|
||||||
name := i.Name()
|
name := i.Name()
|
||||||
ext := filepath.Ext(name)
|
ext := filepath.Ext(name)
|
||||||
|
|
||||||
|
// if the extension is not 'html' then ignore the file
|
||||||
if ext != "html" {
|
if ext != "html" {
|
||||||
log.Printf("[ErrorPages] WARNING: non '.html' file in error pages directory: '%s'\n", name)
|
log.Printf("[ErrorPages] WARNING: ignoring non '.html' file in error pages directory: '%s'\n", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the name can't be
|
||||||
|
nameInt, err := strconv.Atoi(strings.TrimSuffix(name, ".html"))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[ErrorPages] WARNING: ignoring invalid error page in error pages directory: '%s'\n", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if nameInt < 100 || nameInt >= 600 {
|
||||||
|
log.Printf("[ErrorPages] WARNING: ignoring invalid error page in error pages directory must be 100-599: '%s'\n", name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +108,11 @@ func (e *ErrorPages) internalCompile(m map[int]func(rw http.ResponseWriter)) err
|
|||||||
return fmt.Errorf("failed to read html file '%s': %w", name, err)
|
return fmt.Errorf("failed to read html file '%s': %w", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: save to map
|
m[nameInt] = func(rw http.ResponseWriter) {
|
||||||
|
rw.Header().Set("Content-Type", "text/html; encoding=utf-8")
|
||||||
|
rw.WriteHeader(nameInt)
|
||||||
|
_, _ = rw.Write(htmlData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// well no errors happened
|
// well no errors happened
|
||||||
|
@ -22,8 +22,11 @@ func NewHttpsServer(conf *Conf) *http.Server {
|
|||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: conf.HttpsListen,
|
Addr: conf.HttpsListen,
|
||||||
Handler: setupRateLimiter(300).Middleware(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
Handler: setupRateLimiter(300).Middleware(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
rw.Header().Set("Content-Type", "text/html")
|
||||||
rw.WriteHeader(http.StatusNotImplemented)
|
rw.WriteHeader(http.StatusNotImplemented)
|
||||||
|
_, _ = rw.Write([]byte("<pre>"))
|
||||||
_, _ = rw.Write([]byte(fmt.Sprintf("%#v\n", req)))
|
_, _ = rw.Write([]byte(fmt.Sprintf("%#v\n", req)))
|
||||||
|
_, _ = rw.Write([]byte("</pre>"))
|
||||||
_ = r
|
_ = r
|
||||||
// TODO: serve from router and proxy
|
// TODO: serve from router and proxy
|
||||||
// r.ServeHTTP(rw, req)
|
// r.ServeHTTP(rw, req)
|
||||||
|
Loading…
Reference in New Issue
Block a user