mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
Defer eager request body reads and temporary file creation until after authentication or over the 1 MiB in-memory threshold, expire read deadlines and close connections when responses finish with unconsumed request bodies, bound HTTP header and unauthenticated RESP setup reads, and retry transient EMFILE/ENFILE accept errors with exponential backoff. Fixes GHSA-j4xx-x47j-7h54
43 lines
769 B
Go
43 lines
769 B
Go
package api
|
|
|
|
import (
|
|
"bufio"
|
|
"crypto/tls"
|
|
"net"
|
|
)
|
|
|
|
type bufferedConn struct {
|
|
net.Conn
|
|
reader *bufio.Reader
|
|
}
|
|
|
|
func (c *bufferedConn) Read(p []byte) (int, error) {
|
|
if c == nil {
|
|
return 0, net.ErrClosed
|
|
}
|
|
if c.reader == nil {
|
|
return c.Conn.Read(p)
|
|
}
|
|
return c.reader.Read(p)
|
|
}
|
|
|
|
func (c *bufferedConn) ConnectionState() tls.ConnectionState {
|
|
if c == nil || c.Conn == nil {
|
|
return tls.ConnectionState{}
|
|
}
|
|
if stater, ok := c.Conn.(interface{ ConnectionState() tls.ConnectionState }); ok {
|
|
return stater.ConnectionState()
|
|
}
|
|
return tls.ConnectionState{}
|
|
}
|
|
|
|
func (c *bufferedConn) CloseWrite() error {
|
|
if c == nil || c.Conn == nil {
|
|
return nil
|
|
}
|
|
if cw, ok := c.Conn.(interface{ CloseWrite() error }); ok {
|
|
return cw.CloseWrite()
|
|
}
|
|
return nil
|
|
}
|