Skip to content

Commit

Permalink
ReImplement DialTLS fix from apns2 (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
McPo authored May 14, 2020
1 parent 20a9d18 commit b35a831
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion gorush/notification_apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"encoding/base64"
"errors"
"net"
"net/http"
"path/filepath"
"sync"
Expand All @@ -19,7 +20,23 @@ import (
"golang.org/x/net/http2"
)

var idleConnTimeout = 90 * time.Second
var (
idleConnTimeout = 90 * time.Second
tlsDialTimeout = 20 * time.Second
tcpKeepAlive = 60 * time.Second
)

// DialTLS is the default dial function for creating TLS connections for
// non-proxied HTTPS requests.
var DialTLS = func(cfg *tls.Config) func(network, addr string) (net.Conn, error) {
return func(network, addr string) (net.Conn, error) {
dialer := &net.Dialer{
Timeout: tlsDialTimeout,
KeepAlive: tcpKeepAlive,
}
return tls.DialWithDialer(dialer, network, addr, cfg)
}
}

// Sound sets the aps sound on the payload.
type Sound struct {
Expand Down Expand Up @@ -128,6 +145,7 @@ func newApnsClient(certificate tls.Certificate) (*apns2.Client, error) {

transport := &http.Transport{
TLSClientConfig: tlsConfig,
DialTLS: DialTLS(tlsConfig),
Proxy: http.DefaultTransport.(*http.Transport).Proxy,
IdleConnTimeout: idleConnTimeout,
}
Expand Down Expand Up @@ -156,6 +174,7 @@ func newApnsTokenClient(token *token.Token) (*apns2.Client, error) {
}

transport := &http.Transport{
DialTLS: DialTLS(nil),
Proxy: http.DefaultTransport.(*http.Transport).Proxy,
IdleConnTimeout: idleConnTimeout,
}
Expand Down

0 comments on commit b35a831

Please sign in to comment.