mirror of
https://github.com/minio/minio.git
synced 2025-04-22 11:26:36 -04:00
fix: for Target isActive use net.Dial instead (#17251)
This commit is contained in:
parent
9b5829c16e
commit
443250d135
@ -25,6 +25,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -128,34 +129,14 @@ func (target *WebhookTarget) Store() event.TargetStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (target *WebhookTarget) isActive() (bool, error) {
|
func (target *WebhookTarget) isActive() (bool, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
conn, err := net.DialTimeout("tcp", target.args.Endpoint.Host, 5*time.Second)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodHead, target.args.Endpoint.String(), nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if xnet.IsNetworkOrHostDown(err, false) {
|
if xnet.IsNetworkOrHostDown(err, false) {
|
||||||
return false, store.ErrNotConnected
|
return false, store.ErrNotConnected
|
||||||
}
|
}
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
tokens := strings.Fields(target.args.AuthToken)
|
defer conn.Close()
|
||||||
switch len(tokens) {
|
|
||||||
case 2:
|
|
||||||
req.Header.Set("Authorization", target.args.AuthToken)
|
|
||||||
case 1:
|
|
||||||
req.Header.Set("Authorization", "Bearer "+target.args.AuthToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := target.httpClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
if xnet.IsNetworkOrHostDown(err, true) {
|
|
||||||
return false, store.ErrNotConnected
|
|
||||||
}
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
io.Copy(io.Discard, resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
// No network failure i.e response from the target means its up
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user