Support set http proxy for gorush CLI.

only working for GCM protocol.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2016-07-29 08:48:24 +08:00
parent 9112f34b2f
commit e784ae538a
3 changed files with 42 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ import (
apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
"github.com/sideshow/apns2/payload"
"net/http"
"net/url"
"path/filepath"
"time"
)
@@ -116,6 +118,19 @@ func CheckMessage(req PushNotification) error {
return nil
}
func SetProxy(proxy string) error {
proxyUrl, err := url.ParseRequestURI(proxy)
if err != nil {
return err
}
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
return nil
}
// CheckPushConf provide check your yml config.
func CheckPushConf() error {
if !PushConf.Ios.Enabled && !PushConf.Android.Enabled {

View File

@@ -542,3 +542,16 @@ func TestCheckAndroidMessage(t *testing.T) {
success := PushToAndroid(req)
assert.False(t, success)
}
func TestSetProxyURL(t *testing.T) {
err := SetProxy("87.236.233.92:8080")
assert.Error(t, err)
assert.Equal(t, "parse 87.236.233.92:8080: invalid URI for request", err.Error())
err = SetProxy("a.html")
assert.Error(t, err)
err = SetProxy("http://87.236.233.92:8080")
assert.NoError(t, err)
}