Commit 1155b57e8a
Verified · cmc
Layout: unified · split
internal/push/apns.go +14 −1
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | "fmt" | 8 | "fmt" |
| 9 | "io" | 9 | "io" |
| 10 | "net/http" | 10 | "net/http" |
| 11 | "os" | ||
| 11 | "strconv" | 12 | "strconv" |
| 12 | "strings" | 13 | "strings" |
| 13 | "time" | 14 | "time" |
| @@ -45,7 +46,7 @@ func NewClient(cfg config.Push) (*Client, error) { | |||
| 45 | // requires; no explicit http2 transport is needed. | 46 | // requires; no explicit http2 transport is needed. |
| 46 | http: &http.Client{Timeout: 30 * time.Second}, | 47 | http: &http.Client{Timeout: 30 * time.Second}, |
| 47 | host: cfg.Host(), | 48 | host: cfg.Host(), |
| 48 | scheme: "https", | 49 | scheme: apnsScheme(), |
| 49 | topic: cfg.Topic, | 50 | topic: cfg.Topic, |
| 50 | } | 51 | } |
| 51 | if cfg.KeyFile != "" { | 52 | if cfg.KeyFile != "" { |
| @@ -59,6 +60,18 @@ func NewClient(cfg config.Push) (*Client, error) { | |||
| 59 | return c, nil | 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 | // Send delivers one alert. The returned duration is the server's | 75 | // Send delivers one alert. The returned duration is the server's |
| 63 | // Retry-After when it gave one, zero otherwise. | 76 | // Retry-After when it gave one, zero otherwise. |
| 64 | func (c *Client) Send(ctx context.Context, token, title, body, path string) (result, time.Duration, error) { | 77 | func (c *Client) Send(ctx context.Context, token, title, body, path string) (result, time.Duration, error) { |