Skip to content

Commit

Permalink
HTTP transport: Fix an issue when HTTP client start fail with 403 (XT…
Browse files Browse the repository at this point in the history
…LS#3910)

Co-authored-by: RPRX <[email protected]>
  • Loading branch information
2 people authored and leninalive committed Oct 29, 2024
1 parent 998c35f commit d652321
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions transport/internet/http/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in

pconn, err := internet.DialSystem(hctx, net.TCPDestination(address, port), sockopt)
if err != nil {
errors.LogErrorInner(ctx, err, "failed to dial to " + addr)
errors.LogErrorInner(ctx, err, "failed to dial to "+addr)
return nil, err
}

Expand All @@ -156,12 +156,12 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in
cn = tls.Client(pconn, tlsConfig).(*tls.Conn)
}
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
}
if !tlsConfig.InsecureSkipVerify {
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
}
}
Expand Down Expand Up @@ -224,16 +224,20 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
Host: dest.NetAddr(),
Path: httpSettings.getNormalizedPath(),
},
Header: httpHeaders,
Header: httpHeaders,
}
// Disable any compression method from server.
request.Header.Set("Accept-Encoding", "identity")

wrc := &WaitReadCloser{Wait: make(chan struct{})}
go func() {
response, err := client.Do(request)
if err != nil {
errors.LogWarningInner(ctx, err, "failed to dial to ", dest)
if err != nil || response.StatusCode != 200 {
if err != nil {
errors.LogWarningInner(ctx, err, "failed to dial to ", dest)
} else {
errors.LogWarning(ctx, "unexpected status ", response.StatusCode)
}
wrc.Close()
{
// Abandon `client` if `client.Do(request)` failed
Expand All @@ -246,11 +250,6 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
}
return
}
if response.StatusCode != 200 {
errors.LogWarning(ctx, "unexpected status", response.StatusCode)
wrc.Close()
return
}
wrc.Set(response.Body)
}()

Expand Down

0 comments on commit d652321

Please sign in to comment.