public void ParseConfigFileCorrectlyTest() { SecureNativeOptions options = ConfigurationManager.LoadConfig(); Assert.IsNotNull(options); Assert.AreEqual("SOME_API_KEY", options.GetApiKey()); Assert.AreEqual("SOME_API_URL", options.GetApiUrl()); Assert.AreEqual(true, options.IsAutoSend()); Assert.AreEqual(false, options.IsDisabled()); Assert.AreEqual(FailOverStrategy.FAIL_CLOSED, options.GetFailOverStrategy()); Assert.AreEqual(1000, options.GetInterval()); Assert.AreEqual("fatal", options.GetLogLevel()); Assert.AreEqual(100, options.GetMaxEvents()); Assert.AreEqual(1500, options.GetTimeout()); Assert.AreEqual(1, options.GetProxyHeaders().Length); }
public static string GetClientIpFromRequest(HttpRequest request, SecureNativeOptions options) { if (options?.GetProxyHeaders().Length > 0) { foreach (var header in options.GetProxyHeaders()) { if (request.Headers[header].ToArray() == null) { continue; } var extracted = GetValidIp(request.Headers[header].ToArray()); if (!string.IsNullOrEmpty(extracted)) { return(extracted); } } } try { foreach (var header in IpHeaders.Where(header => request.Headers[header].Count > 0)) { var extracted = GetValidIp(request.Headers[header].ToArray()); if (!string.IsNullOrEmpty(extracted)) { return(extracted); } } if (request.HttpContext.Connection.LocalIpAddress != null) { return(request.HttpContext.Connection.LocalIpAddress.ToString()); } } catch (Exception) { return(string.Empty); } return(string.Empty); }
public static string GetClientIpFromRequest(HttpWebRequest request, SecureNativeOptions options) { if (options?.GetProxyHeaders().Length > 0) { foreach (var header in options.GetProxyHeaders()) { if (string.IsNullOrEmpty(request.Headers.Get(header))) { continue; } var ips = request.Headers.Get(header).Split(","); var extracted = GetValidIp(ips); if (!string.IsNullOrEmpty(extracted)) { return(extracted); } } } try { foreach (var header in IpHeaders.Where(header => request.Headers.Get(header) != null)) { var ips = request.Headers.Get(header).Split(","); var extracted = GetValidIp(ips); if (!string.IsNullOrEmpty(extracted)) { return(extracted); } } } catch (Exception) { return(string.Empty); } return(string.Empty); }