mirror of
https://github.com/1f349/violet.git
synced 2024-11-21 10:51:40 +00:00
Minor changes to error page loading code
This commit is contained in:
parent
61097981d6
commit
71f8aaaf16
@ -6,6 +6,8 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@ -82,8 +84,21 @@ func (e *ErrorPages) internalCompile(m map[int]func(rw http.ResponseWriter)) err
|
||||
// get file name and extension
|
||||
name := i.Name()
|
||||
ext := filepath.Ext(name)
|
||||
|
||||
// if the extension is not 'html' then ignore the file
|
||||
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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -22,8 +22,11 @@ func NewHttpsServer(conf *Conf) *http.Server {
|
||||
s := &http.Server{
|
||||
Addr: conf.HttpsListen,
|
||||
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.Write([]byte("<pre>"))
|
||||
_, _ = rw.Write([]byte(fmt.Sprintf("%#v\n", req)))
|
||||
_, _ = rw.Write([]byte("</pre>"))
|
||||
_ = r
|
||||
// TODO: serve from router and proxy
|
||||
// r.ServeHTTP(rw, req)
|
||||
|
Loading…
Reference in New Issue
Block a user