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:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user