proxy: optimize NewConn, avoid loop

This commit is contained in:
nadoo committed 2020-10-11 18:46:15 +08:00
1 parent 40ddd1be3a
commit 6fff126e4b
6 files changed
+14 -13

No files matched your search

+3 -9
View File
@@ -45,17 +45,11 @@ func (s *HTTP) ListenAndServe() {
func (s *HTTP) Serve(cc net.Conn) {
defer cc.Close()
var c *proxy.Conn
switch cc := cc.(type) {
case *proxy.Conn:
c = cc
case *net.TCPConn:
cc.SetKeepAlive(true)
c = proxy.NewConn(cc)
default:
c = proxy.NewConn(cc)
if c, ok := cc.(*net.TCPConn); ok {
c.SetKeepAlive(true)
}
c := proxy.NewConn(cc)
req, err := parseRequest(c.Reader())
if err != nil {
log.F("[http] can not parse request from %s", c.RemoteAddr())