mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.ReadResponse(bufio.NewReader(rawConn), req) // nolint: bodyclose
|
resp, err := http.ReadResponse(bufio.NewReader(rawConn), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawConn.Close()
|
rawConn.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
rawConn.Close()
|
rawConn.Close()
|
||||||
|
@ -279,7 +279,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|||||||
|
|
||||||
responseDone := func() error {
|
responseDone := func() error {
|
||||||
responseReader := bufio.NewReaderSize(&buf.BufferedReader{Reader: link.Reader}, buf.Size)
|
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 {
|
if err == nil {
|
||||||
http_proto.RemoveHopByHopHeaders(response.Header)
|
http_proto.RemoveHopByHopHeaders(response.Header)
|
||||||
if response.ContentLength >= 0 {
|
if response.ContentLength >= 0 {
|
||||||
@ -291,6 +291,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|||||||
response.Close = true
|
response.Close = true
|
||||||
result = nil
|
result = nil
|
||||||
}
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
} else {
|
} else {
|
||||||
newError("failed to read response from ", request.Host).Base(err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
|
newError("failed to read response from ", request.Host).Base(err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
|
||||||
response = &http.Response{
|
response = &http.Response{
|
||||||
|
@ -129,7 +129,7 @@ func TestHttpError(t *testing.T) {
|
|||||||
Transport: transport,
|
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)
|
common.Must(err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != 503 {
|
if resp.StatusCode != 503 {
|
||||||
|
Loading…
Reference in New Issue
Block a user