Commit 1155b57e8a
Verified · cmc
internal/push/apns.go +14 −1
| @@ -8,6 +8,7 @@ import ( | ||
| 8 | 8 | "fmt" |
| 9 | 9 | "io" |
| 10 | 10 | "net/http" |
| 11 | "os" | |
| 11 | 12 | "strconv" |
| 12 | 13 | "strings" |
| 13 | 14 | "time" |
| @@ -45,7 +46,7 @@ func NewClient(cfg config.Push) (*Client, error) { | ||
| 45 | 46 | // requires; no explicit http2 transport is needed. |
| 46 | 47 | http: &http.Client{Timeout: 30 * time.Second}, |
| 47 | 48 | host: cfg.Host(), |
| 48 | scheme: "https", | |
| 49 | scheme: apnsScheme(), | |
| 49 | 50 | topic: cfg.Topic, |
| 50 | 51 | } |
| 51 | 52 | if cfg.KeyFile != "" { |
| @@ -59,6 +60,18 @@ func NewClient(cfg config.Push) (*Client, error) { | ||
| 59 | 60 | return c, nil |
| 60 | 61 | } |
| 61 | 62 | |
| 63 | // apnsScheme is https for the real Apple hosts. GITBAY_APNS_HOST redirects | |
| 64 | // the endpoint for tests (config.Push.Host), and the fake it points at | |
| 65 | // speaks plain HTTP/1.1 rather than negotiating TLS, so the same override | |
| 66 | // has to drop the scheme too, or every request fails with "server gave | |
| 67 | // HTTP response to HTTPS client" instead of reaching the fake at all. | |
| 68 | func apnsScheme() string { | |
| 69 | if os.Getenv("GITBAY_APNS_HOST") != "" { | |
| 70 | return "http" | |
| 71 | } | |
| 72 | return "https" | |
| 73 | } | |
| 74 | ||
| 62 | 75 | // Send delivers one alert. The returned duration is the server's |
| 63 | 76 | // Retry-After when it gave one, zero otherwise. |
| 64 | 77 | func (c *Client) Send(ctx context.Context, token, title, body, path string) (result, time.Duration, error) { |