Skip to content

Commit

Permalink
Take as self request if URL path seem like getting PAC.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Aug 22, 2013
1 parent 49b56b6 commit 377fd4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pac.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ func initPAC() {
}()
}

func sendPAC(c *clientConn) {
if _, err := c.Write(genPAC(c)); err != nil {
debug.Println("Error sending PAC file")
return
func sendPAC(c *clientConn) error {
_, err := c.Write(genPAC(c))
if err != nil {
debug.Printf("cli(%s) error sending PAC:", c.RemoteAddr(), err)
}
return err
}
9 changes: 8 additions & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ func isSelfRequest(r *Request) bool {
}
// Maxthon sometimes sends requests without host in request line,
// in that case, get host information from Host header.
// But if client PAC setting is using cow server's DNS name, we can't
// decide if the request is for cow itself (need reverse lookup).
// So if request path seems like getting PAC, simply return true.
if r.URL.Path == "/pac" || strings.HasPrefix(r.URL.Path, "/pac?") {
return true
}
r.URL.ParseHostPort(r.Header.Host)
if selfListenAddr[r.URL.Host] {
return true
Expand All @@ -229,7 +235,8 @@ func (c *clientConn) serveSelfURL(r *Request) (err error) {
}
if r.URL.Path == "/pac" || strings.HasPrefix(r.URL.Path, "/pac?") {
sendPAC(c)
// Send non nil error to close client connection.
// PAC header contains connection close, send non nil error to close
// client connection.
return errPageSent
}
end:
Expand Down

0 comments on commit 377fd4e

Please sign in to comment.