mirror of
https://github.com/zhigang1992/cow.git
synced 2026-01-12 22:46:29 +08:00
Show host name in error page.
This commit is contained in:
32
error.go
32
error.go
@@ -3,22 +3,11 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errPageRawTmpl = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head> <title>COW Proxy</title> </head>
|
||||
<body>
|
||||
<h1>{{.H1}}</h1>
|
||||
{{.Msg}}
|
||||
<hr />
|
||||
Generated by <i>COW ` + version + `</i> at {{.T}}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
// Do not end with "\r\n" so we can add more header later
|
||||
var headRawTmpl = "HTTP/1.1 {{.CodeReason}}\r\n" +
|
||||
"Connection: keep-alive\r\n" +
|
||||
@@ -30,7 +19,24 @@ var headRawTmpl = "HTTP/1.1 {{.CodeReason}}\r\n" +
|
||||
var errPageTmpl, headTmpl *template.Template
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
hostName, err := os.Hostname()
|
||||
if err != nil {
|
||||
hostName = "unknown host"
|
||||
}
|
||||
|
||||
errPageRawTmpl := `<!DOCTYPE html>
|
||||
<html>
|
||||
<head> <title>COW Proxy</title> </head>
|
||||
<body>
|
||||
<h1>{{.H1}}</h1>
|
||||
{{.Msg}}
|
||||
<hr />
|
||||
Generated by <i>COW ` + version + `</i> <br />
|
||||
Host <i>` + hostName + `</i> <br />
|
||||
{{.T}}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
if headTmpl, err = template.New("errorHead").Parse(headRawTmpl); err != nil {
|
||||
Fatal("Internal error on generating error head template")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user