1
0

Added NotFound handler.

Removed commented out content-type header.
This commit is contained in:
Alexander Andreev 2022-02-07 22:51:47 +04:00
parent a5f73e0d60
commit 8fdf0b61e2
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -23,6 +23,10 @@ var defaultAmberOptions = amber.Options{PrettyPrint: false, LineNumbers: false}
var compiledTemplates map[string]*template.Template var compiledTemplates map[string]*template.Template
type NotFoundData struct {
MainSite string
}
type IndexData struct { type IndexData struct {
MainSite string MainSite string
FileMaxSz string FileMaxSz string
@ -176,7 +180,6 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
} }
w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", name)) w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", name))
// w.Header().Add("Content-Type", "application/octet-stream")
fd, err := os.Open(path) fd, err := os.Open(path)
if err != nil { if err != nil {
@ -190,3 +193,13 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
http.ServeContent(w, r, path, stat.ModTime(), fd) http.ServeContent(w, r, path, stat.ModTime(), fd)
} }
func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
if err := compiledTemplates["404"].Execute(w, NotFoundData{
MainSite: utils.MainSite(r.Host),
}); err != nil {
w.WriteHeader(http.StatusInternalServerError)
h.logErr.Fatalln("failed to execute 404 template:", err)
}
}