mirror of
https://github.com/zhigang1992/cow.git
synced 2026-01-12 22:46:29 +08:00
Reuse server buffer in copyServer2Client.
This commit is contained in:
15
proxy.go
15
proxy.go
@@ -42,7 +42,11 @@ func freeBuf(b []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
// Close client connection if no new request received in some time.
|
||||
// Close client connection if no new request received in some time. Keep it
|
||||
// small to avoid keeping too many client connections (which associates with
|
||||
// server connections) and lead to too much open file error. On OS X, the
|
||||
// default soft limit of open file descriptor is 256, which is really
|
||||
// conservative.
|
||||
const clientConnTimeout = 10 * time.Second
|
||||
const keepAliveHeader = "Keep-Alive: timeout=10\r\n"
|
||||
|
||||
@@ -719,13 +723,8 @@ func (sv *serverConn) mayBeClosed() bool {
|
||||
}
|
||||
|
||||
func copyServer2Client(sv *serverConn, c *clientConn, r *Request) (err error) {
|
||||
// For connect, the data read each time is usually less than 4096. Little
|
||||
// benefit to increase this to 8192.
|
||||
buf := getBuf()
|
||||
defer func() {
|
||||
freeBuf(buf)
|
||||
}()
|
||||
sv.bufRd = nil
|
||||
sv.bufRd = nil // Use buffer from server connection
|
||||
buf := sv.buf
|
||||
var n int
|
||||
|
||||
/*
|
||||
|
||||
@@ -57,12 +57,14 @@ test_get() {
|
||||
}
|
||||
|
||||
test_get $PROXY_ADDR/pac "apple.com" "noproxy" # test for pac
|
||||
test_get google.com "</html>" # 301 redirect
|
||||
test_get www.google.com "</html>" # 302 redirect , chunked encoding
|
||||
test_get google.com "<html" # 301 redirect
|
||||
test_get www.google.com "<html" # 302 redirect , chunked encoding
|
||||
test_get www.reddit.com "<html" # chunked encoding
|
||||
test_get https://www.twitter.com "</html>" # builtin blocked site, HTTP CONNECT
|
||||
test_get openvpn.net "</html>" # blocked site, all kinds of block method
|
||||
test_get http://plan9.bell-labs.com/magic/man2html/1/2l "<head>" "" "404" # single LF in response header
|
||||
test_get plan9.bell-labs.com/magic/man2html/1/2l "<head>" "" "404" # single LF in response header
|
||||
test_get https://google.com "<html" # test for HTTP connect
|
||||
test_get https://www.google.com "<html"
|
||||
test_get https://www.twitter.com "</html>"
|
||||
|
||||
# Chinese sites may timeout on travis.
|
||||
if [[ -z $TRAVIS ]]; then
|
||||
|
||||
Reference in New Issue
Block a user