Browse Source

Status code 404 for custom error 404 page

Vova Tkach 6 years ago
parent
commit
6ad9466f6c
1 changed files with 5 additions and 8 deletions
  1. 5 8
      engine/wrapper/static.go

+ 5 - 8
engine/wrapper/static.go

@@ -2,6 +2,7 @@ package wrapper
 
 import (
 	"fmt"
+	"io/ioutil"
 	"net/http"
 	"os"
 
@@ -88,16 +89,12 @@ func (e *Wrapper) printPageDefault() {
 }
 
 func (e *Wrapper) printPage404() {
-	// TODO: Fix this
-	// http: multiple response.WriteHeader calls
-	// (*e.W).WriteHeader(http.StatusNotFound)
-
 	// Custom 404 error page
-	f, err := os.Open(e.DirVhostHome + "/htdocs" + "/404.html")
+	f, err := ioutil.ReadFile(e.DirVhostHome + "/htdocs" + "/404.html")
 	if err == nil {
-		defer f.Close()
-		// TODO: set status code 404 here
-		http.ServeFile(*e.W, e.R, e.DirVhostHome+"/htdocs"+"/404.html")
+		(*e.W).WriteHeader(http.StatusNotFound)
+		(*e.W).Header().Set("Content-Type", "text/html")
+		(*e.W).Write(f)
 		return
 	}