- For OnlineConfigResolver and GeositeUpdatertags/4.2.1.0
@@ -102,6 +102,8 @@ namespace Shadowsocks.Controller | |||||
// because we can't change proxy on existing socketsHttpHandler instance | // because we can't change proxy on existing socketsHttpHandler instance | ||||
httpClientHandler = new HttpClientHandler(); | httpClientHandler = new HttpClientHandler(); | ||||
httpClient = new HttpClient(httpClientHandler); | httpClient = new HttpClient(httpClientHandler); | ||||
if (!string.IsNullOrWhiteSpace(config.userAgentString)) | |||||
httpClient.DefaultRequestHeaders.Add("User-Agent", config.userAgentString); | |||||
if (config.enabled) | if (config.enabled) | ||||
{ | { | ||||
httpClientHandler.Proxy = new WebProxy( | httpClientHandler.Proxy = new WebProxy( | ||||
@@ -11,7 +11,7 @@ namespace Shadowsocks.Controller.Service | |||||
{ | { | ||||
public class OnlineConfigResolver | public class OnlineConfigResolver | ||||
{ | { | ||||
public static async Task<List<Server>> GetOnline(string url, IWebProxy proxy = null) | |||||
public static async Task<List<Server>> GetOnline(string url, string userAgentString, IWebProxy proxy = null) | |||||
{ | { | ||||
var httpClientHandler = new HttpClientHandler() | var httpClientHandler = new HttpClientHandler() | ||||
{ | { | ||||
@@ -21,9 +21,8 @@ namespace Shadowsocks.Controller.Service | |||||
{ | { | ||||
Timeout = TimeSpan.FromSeconds(15) | Timeout = TimeSpan.FromSeconds(15) | ||||
}; | }; | ||||
string userAgent = "ShadowsocksWindows/" + UpdateChecker.Version; | |||||
httpClient.DefaultRequestHeaders.Add("User-Agent", userAgent); | |||||
if (!string.IsNullOrWhiteSpace(userAgentString)) | |||||
httpClient.DefaultRequestHeaders.Add("User-Agent", userAgentString); | |||||
string server_json = await httpClient.GetStringAsync(url); | string server_json = await httpClient.GetStringAsync(url); | ||||
@@ -691,7 +691,7 @@ namespace Shadowsocks.Controller | |||||
public async Task<int> UpdateOnlineConfigInternal(string url) | public async Task<int> UpdateOnlineConfigInternal(string url) | ||||
{ | { | ||||
var onlineServer = await OnlineConfigResolver.GetOnline(url, _config.WebProxy); | |||||
var onlineServer = await OnlineConfigResolver.GetOnline(url, _config.userAgentString, _config.WebProxy); | |||||
_config.configs = Configuration.SortByOnlineConfig( | _config.configs = Configuration.SortByOnlineConfig( | ||||
_config.configs | _config.configs | ||||
.Where(c => c.group != url) | .Where(c => c.group != url) | ||||
@@ -46,6 +46,7 @@ namespace Shadowsocks.Model | |||||
public string geositeUrl; // for custom geosite source (and rule group) | public string geositeUrl; // for custom geosite source (and rule group) | ||||
public string geositeGroup; | public string geositeGroup; | ||||
public bool geositeBlacklistMode; | public bool geositeBlacklistMode; | ||||
public string userAgent; | |||||
//public NLogConfig.LogLevel logLevel; | //public NLogConfig.LogLevel logLevel; | ||||
public LogViewerConfig logViewer; | public LogViewerConfig logViewer; | ||||
@@ -81,6 +82,7 @@ namespace Shadowsocks.Model | |||||
geositeUrl = ""; | geositeUrl = ""; | ||||
geositeGroup = "geolocation-!cn"; | geositeGroup = "geolocation-!cn"; | ||||
geositeBlacklistMode = true; | geositeBlacklistMode = true; | ||||
userAgent = "ShadowsocksWindows/$version"; | |||||
logViewer = new LogViewerConfig(); | logViewer = new LogViewerConfig(); | ||||
proxy = new ProxyConfig(); | proxy = new ProxyConfig(); | ||||
@@ -92,6 +94,9 @@ namespace Shadowsocks.Model | |||||
onlineConfigSource = new List<string>(); | onlineConfigSource = new List<string>(); | ||||
} | } | ||||
[JsonIgnore] | |||||
public string userAgentString; // $version substituted with numeral version in it | |||||
[JsonIgnore] | [JsonIgnore] | ||||
NLogConfig nLogConfig; | NLogConfig nLogConfig; | ||||
@@ -153,6 +158,7 @@ namespace Shadowsocks.Model | |||||
string configContent = File.ReadAllText(CONFIG_FILE); | string configContent = File.ReadAllText(CONFIG_FILE); | ||||
config = JsonConvert.DeserializeObject<Configuration>(configContent); | config = JsonConvert.DeserializeObject<Configuration>(configContent); | ||||
config.isDefault = false; | config.isDefault = false; | ||||
config.version = UpdateChecker.Version; | |||||
if (UpdateChecker.Asset.CompareVersion(UpdateChecker.Version, config.version ?? "0") > 0) | if (UpdateChecker.Asset.CompareVersion(UpdateChecker.Version, config.version ?? "0") > 0) | ||||
{ | { | ||||
config.updated = true; | config.updated = true; | ||||
@@ -201,6 +207,8 @@ namespace Shadowsocks.Model | |||||
logger.Error(e, "Cannot get the log level from NLog config file. Please check if the nlog config file exists with corresponding XML nodes."); | logger.Error(e, "Cannot get the log level from NLog config file. Please check if the nlog config file exists with corresponding XML nodes."); | ||||
} | } | ||||
config.userAgentString = config.userAgent.Replace("$version", config.version); | |||||
return config; | return config; | ||||
} | } | ||||