mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
Fix: close response body (#484)
This commit is contained in:
parent
45aeaa8080
commit
5e99737c12
@ -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()
|
||||
|
@ -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{
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user