From 7ea034976a8d7a46cff6ef35c7d330fb63a34f83 Mon Sep 17 00:00:00 2001 From: Timothy Date: Mon, 2 Sep 2019 19:05:35 +0800 Subject: [PATCH] add customized user-agent --- config_sample.json | 1 + handler/google/google_handler.go | 6 +++++- settings.go | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config_sample.json b/config_sample.json index b25e1ae..3d57809 100644 --- a/config_sample.json +++ b/config_sample.json @@ -20,6 +20,7 @@ ], "ip_url": "https://myip.biturl.top", "interval": 300, + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36", "ip_interface": "eth0", "socks5_proxy": "", "notify": { diff --git a/handler/google/google_handler.go b/handler/google/google_handler.go index cd4c0b7..5583eee 100644 --- a/handler/google/google_handler.go +++ b/handler/google/google_handler.go @@ -82,8 +82,12 @@ func (handler *Handler) UpdateIP(domain, subDomain, currentIP string) { values.Add("myip", currentIP) client := godns.GetHttpClient(handler.Configuration) - req, _ := http.NewRequest("POST", GoogleUrl, strings.NewReader(values.Encode())) + + if handler.Configuration.UserAgent != "" { + req.Header.Add("User-Agent", handler.Configuration.UserAgent) + } + resp, err := client.Do(req) if err != nil { diff --git a/settings.go b/settings.go index 40ab6f7..1c3411c 100644 --- a/settings.go +++ b/settings.go @@ -31,6 +31,7 @@ type Settings struct { Domains []Domain `json:"domains"` IPUrl string `json:"ip_url"` Interval int `json:"interval"` + UserAgent string `json:"user_agent,omitempty"` LogPath string `json:"log_path"` Socks5Proxy string `json:"socks5_proxy"` Notify Notify `json:"notify"`