mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-25 06:36:05 +03:00
HTTP transport: Fix an issue when HTTP client start fail with 403 (#3910)
Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
parent
8c180b9cfd
commit
6a70ae6408
@ -141,7 +141,7 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in
|
|||||||
|
|
||||||
pconn, err := internet.DialSystem(hctx, net.TCPDestination(address, port), sockopt)
|
pconn, err := internet.DialSystem(hctx, net.TCPDestination(address, port), sockopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.LogErrorInner(ctx, err, "failed to dial to " + addr)
|
errors.LogErrorInner(ctx, err, "failed to dial to "+addr)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,12 +156,12 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in
|
|||||||
cn = tls.Client(pconn, tlsConfig).(*tls.Conn)
|
cn = tls.Client(pconn, tlsConfig).(*tls.Conn)
|
||||||
}
|
}
|
||||||
if err := cn.HandshakeContext(ctx); err != nil {
|
if err := cn.HandshakeContext(ctx); err != nil {
|
||||||
errors.LogErrorInner(ctx, err, "failed to dial to " + addr)
|
errors.LogErrorInner(ctx, err, "failed to dial to "+addr)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !tlsConfig.InsecureSkipVerify {
|
if !tlsConfig.InsecureSkipVerify {
|
||||||
if err := cn.VerifyHostname(tlsConfig.ServerName); err != nil {
|
if err := cn.VerifyHostname(tlsConfig.ServerName); err != nil {
|
||||||
errors.LogErrorInner(ctx, err, "failed to dial to " + addr)
|
errors.LogErrorInner(ctx, err, "failed to dial to "+addr)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,8 +232,12 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
wrc := &WaitReadCloser{Wait: make(chan struct{})}
|
wrc := &WaitReadCloser{Wait: make(chan struct{})}
|
||||||
go func() {
|
go func() {
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
|
if err != nil || response.StatusCode != 200 {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.LogWarningInner(ctx, err, "failed to dial to ", dest)
|
errors.LogWarningInner(ctx, err, "failed to dial to ", dest)
|
||||||
|
} else {
|
||||||
|
errors.LogWarning(ctx, "unexpected status ", response.StatusCode)
|
||||||
|
}
|
||||||
wrc.Close()
|
wrc.Close()
|
||||||
{
|
{
|
||||||
// Abandon `client` if `client.Do(request)` failed
|
// Abandon `client` if `client.Do(request)` failed
|
||||||
@ -246,11 +250,6 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if response.StatusCode != 200 {
|
|
||||||
errors.LogWarning(ctx, "unexpected status", response.StatusCode)
|
|
||||||
wrc.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wrc.Set(response.Body)
|
wrc.Set(response.Body)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user