1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00

Fix: close response body (#484)

This commit is contained in:
Loyalsoldier 2020-12-03 16:07:41 +08:00 committed by GitHub
parent 45aeaa8080
commit 5e99737c12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -164,11 +164,12 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
return nil, err
}
resp, err := http.ReadResponse(bufio.NewReader(rawConn), req) // nolint: bodyclose
resp, err := http.ReadResponse(bufio.NewReader(rawConn), req)
if err != nil {
rawConn.Close()
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
rawConn.Close()

View File

@ -279,7 +279,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
responseDone := func() error {
responseReader := bufio.NewReaderSize(&buf.BufferedReader{Reader: link.Reader}, buf.Size)
response, err := http.ReadResponse(responseReader, request) // nolint: bodyclose
response, err := http.ReadResponse(responseReader, request)
if err == nil {
http_proto.RemoveHopByHopHeaders(response.Header)
if response.ContentLength >= 0 {
@ -291,6 +291,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
response.Close = true
result = nil
}
defer response.Body.Close()
} else {
newError("failed to read response from ", request.Host).Base(err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
response = &http.Response{

View File

@ -129,7 +129,7 @@ func TestHttpError(t *testing.T) {
Transport: transport,
}
resp, err := client.Get("http://127.0.0.1:" + dest.Port.String()) // nolint: bodyclose
resp, err := client.Get("http://127.0.0.1:" + dest.Port.String())
common.Must(err)
defer resp.Body.Close()
if resp.StatusCode != 503 {