Better error page message.

This commit is contained in:
Chen Yufei
2012-11-09 01:32:23 +08:00
parent 2cda704448
commit fb37e9b0d3
4 changed files with 16 additions and 12 deletions

View File

@@ -3,7 +3,6 @@ package main
import (
"bufio"
"io"
"net"
"os"
"path"
"sort"
@@ -190,10 +189,6 @@ func writeDomainList(fpath string, lst []string) (err error) {
return
}
func hostIsIP(host string) bool {
return net.ParseIP(host) != nil
}
func host2Domain(host string) (domain string) {
dotPos := strings.LastIndex(host, ".")
if dotPos == -1 {

View File

@@ -4,8 +4,8 @@ import (
"bufio"
"bytes"
"fmt"
"html/template"
"os"
"text/template"
"time"
)
@@ -13,9 +13,8 @@ var htmlRawTemplate = `<!DOCTYPE html>
<html>
<head> <title>Proxy error</title> </head>
<body>
<h1>Proxy Error: {{.H1}}</h1>
<h1>[Error] {{.H1}}</h1>
{{.Msg}}
<br /> <br />
<hr />
Generated by <i>cow-proxy</i> at {{.T}}
</body>

View File

@@ -252,14 +252,20 @@ func (c *clientConn) readResponse(srvReader *bufio.Reader, handler *Handler) (er
// GFW may connection reset here, may also make it time out Is
// it normal for connection to a site timeout? If so, it's
// better not add it to blocked site
host, _ := splitHostPort(r.URL.Host)
detailMsg := fmt.Sprintf("<p>HTTP Request <strong>%v</strong></p>", r)
if !hostIsIP(host) {
detailMsg += fmt.Sprintf(
"<p>Domain <strong>%s</strong> added to blocked list. Try to refresh.</p>", host)
}
if ne.Err == syscall.ECONNRESET {
addBlockedRequest(r)
sendErrorPage(c.buf.Writer, "503", "Connection reset",
ne.Error(), r.String())
ne.Error(), detailMsg)
} else if ne.Timeout() {
addBlockedRequest(r)
sendErrorPage(c.buf.Writer, "504", "Time out reading response",
ne.Error(), r.String())
ne.Error(), detailMsg)
}
}
return
@@ -372,7 +378,7 @@ func (c *clientConn) createHandler(r *Request) (*Handler, error) {
connDone:
if connFailed {
sendErrorPage(c.buf.Writer, "504", "Connection failed", err.Error(),
fmt.Sprintf("Failed connect to %s for request: %v", r.URL.Host, r))
fmt.Sprintf("<p>HTTP Request <strong>%v</strong></p>", r))
return nil, err
}
@@ -586,3 +592,7 @@ func sendBody(w *bufio.Writer, r *bufio.Reader, chunk bool, contLen int64) (err
}
return
}
func hostIsIP(host string) bool {
return net.ParseIP(host) != nil
}

View File

@@ -100,7 +100,7 @@ func createSocksConnection(hostFull string) (c net.Conn, ct connectionType, err
if err != io.EOF {
errl.Printf("Read socks reply err %v n %d\n", err, n)
}
return
return nil, ct, errors.New("Connection failed (by socks server). No such host?")
}
// debug.Printf("Socks reply length %d\n", n)