Fix http response check

Co-authored-by: armv9 <48624112+arm64v8a@users.noreply.github.com>
This commit is contained in:
世界 2023-04-21 17:44:05 +08:00
parent bbdd495ed5
commit df0eef770e
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 8 additions and 3 deletions

View file

@ -12,6 +12,7 @@ import (
"github.com/sagernet/sing-box/common/tls"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/transport/v2rayhttp"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
@ -92,10 +93,13 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
conn := newLateGunConn(pipeInWriter)
go func() {
response, err := c.transport.RoundTrip(request)
if err == nil {
conn.setup(response.Body, nil)
} else {
if err != nil {
conn.setup(nil, err)
} else if response.StatusCode != 200 {
response.Body.Close()
conn.setup(nil, E.New("unexpected status: ", response.StatusCode, " ", response.Status))
} else {
conn.setup(response.Body, nil)
}
}()
return conn, nil

View file

@ -145,6 +145,7 @@ func (c *Client) dialHTTP2(ctx context.Context) (net.Conn, error) {
if err != nil {
conn.setup(nil, err)
} else if response.StatusCode != 200 {
response.Body.Close()
conn.setup(nil, E.New("unexpected status: ", response.StatusCode, " ", response.Status))
} else {
conn.setup(response.Body, nil)