Browse Source

Fix multiple headers error

Vova Tkach 6 years ago
parent
commit
5b2b030d6f
2 changed files with 4 additions and 4 deletions
  1. 2 1
      engine/wrapper/wrapper.go
  2. 2 3
      modules/module_index.go

+ 2 - 1
engine/wrapper/wrapper.go

@@ -189,7 +189,7 @@ func (this *Wrapper) RenderToString(tcont []byte, data interface{}) string {
 	return tpl.String()
 	return tpl.String()
 }
 }
 
 
-func (this *Wrapper) RenderFrontEnd(tname string, data interface{}) {
+func (this *Wrapper) RenderFrontEnd(tname string, data interface{}, status int) {
 	tmpl, err := template.ParseFiles(
 	tmpl, err := template.ParseFiles(
 		this.DTemplate+string(os.PathSeparator)+tname+".html",
 		this.DTemplate+string(os.PathSeparator)+tname+".html",
 		this.DTemplate+string(os.PathSeparator)+"header.html",
 		this.DTemplate+string(os.PathSeparator)+"header.html",
@@ -201,6 +201,7 @@ func (this *Wrapper) RenderFrontEnd(tname string, data interface{}) {
 		utils.SystemErrorPageTemplate(this.W, err)
 		utils.SystemErrorPageTemplate(this.W, err)
 		return
 		return
 	}
 	}
+	this.W.WriteHeader(status)
 	this.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	this.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	this.W.Header().Set("Content-Type", "text/html; charset=utf-8")
 	this.W.Header().Set("Content-Type", "text/html; charset=utf-8")
 	var tpl bytes.Buffer
 	var tpl bytes.Buffer

+ 2 - 3
modules/module_index.go

@@ -67,8 +67,7 @@ func (this *Modules) RegisterModule_Index() *Module {
 			return
 			return
 		} else if err == sql.ErrNoRows {
 		} else if err == sql.ErrNoRows {
 			// User error 404 page
 			// User error 404 page
-			wrap.W.WriteHeader(http.StatusNotFound)
-			wrap.RenderFrontEnd("404", fetdata.New(wrap, nil, true))
+			wrap.RenderFrontEnd("404", fetdata.New(wrap, nil, true), http.StatusNotFound)
 			return
 			return
 		}
 		}
 
 
@@ -84,7 +83,7 @@ func (this *Modules) RegisterModule_Index() *Module {
 		}
 		}
 
 
 		// Render template
 		// Render template
-		wrap.RenderFrontEnd(tmpl_name, fetdata.New(wrap, row, false))
+		wrap.RenderFrontEnd(tmpl_name, fetdata.New(wrap, row, false), http.StatusOK)
 	}, func(wrap *wrapper.Wrapper) (string, string, string) {
 	}, func(wrap *wrapper.Wrapper) (string, string, string) {
 		content := ""
 		content := ""
 		sidebar := ""
 		sidebar := ""