[英]how to check if hostname verification takes place during TLS/SSL handshake?
[英]How to check if error is tls handshake timeout in Go
我有以下代碼向URL請求並檢查錯誤。
import "net/http"
response, err := http.Head("url")
如何檢查錯誤是否是由於tls握手超時引起的? 我嘗試了以下方法:
if err != nil {
tlsError, ok := err.(http.tlsHandshakeTimeoutError)
if ok {
// handle the error
}
}
但是我無法訪問http.tlsHandshakeTimeoutError
類型,因為它未導出。 我還能如何檢查go中的錯誤類型?
是tlsHandshakeTimeoutError
不導出,並且檢查此錯誤的唯一可能性是:
import "net/url"
// ....
if urlError,ok := err.(*url.Error) ; ok {
if urlError.Error() == "net/http: TLS handshake timeout" {
// handle the error
}
}
這是關於它的討論的公開票:
https://github.com/golang/go/issues/15935
順便說一下, http
錯誤(還有tlsHandshakeTimeoutError
還提供:
type WithTimeout interface {
Timeout() bool
}
您可以使用它來檢查是否不喜歡字符串比較。 這是來自http2包的isTemporary實現的示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.