Improve APNs http2 connection health check (#568)

This commit is contained in:
tomoya yokota 2021-05-04 22:26:00 +09:00 committed by GitHub
parent 9c51cbc989
commit 01aba27bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 7 deletions

View File

@ -117,6 +117,10 @@ func InitAPNSClient() error {
ApnsClient, err = newApnsClient(certificateKey)
}
if h2Transport, ok := ApnsClient.HTTPClient.Transport.(*http2.Transport); ok {
configureHTTP2ConnHealthCheck(h2Transport)
}
if err != nil {
LogError.Error("Transport Error:", err.Error())
@ -155,11 +159,11 @@ func newApnsClient(certificate tls.Certificate) (*apns2.Client, error) {
IdleConnTimeout: idleConnTimeout,
}
transportErr := http2.ConfigureTransport(transport)
if transportErr != nil {
return nil, transportErr
if h2Transport, err := http2.ConfigureTransports(transport); err != nil {
return nil, err
} else {
configureHTTP2ConnHealthCheck(h2Transport)
}
client.HTTPClient.Transport = transport
return client, nil
@ -184,9 +188,10 @@ func newApnsTokenClient(token *token.Token) (*apns2.Client, error) {
IdleConnTimeout: idleConnTimeout,
}
transportErr := http2.ConfigureTransport(transport)
if transportErr != nil {
return nil, transportErr
if h2Transport, err := http2.ConfigureTransports(transport); err != nil {
return nil, err
} else {
configureHTTP2ConnHealthCheck(h2Transport)
}
client.HTTPClient.Transport = transport
@ -194,6 +199,11 @@ func newApnsTokenClient(token *token.Token) (*apns2.Client, error) {
return client, nil
}
func configureHTTP2ConnHealthCheck(h2Transport *http2.Transport) {
h2Transport.ReadIdleTimeout = 1 * time.Second
h2Transport.PingTimeout = 1 * time.Second
}
func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload.Payload {
// Alert dictionary