Skip to content

Commit

Permalink
rm ip limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-k123 committed Nov 27, 2024
1 parent 0573e8f commit beeed16
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/CAVerifierServer.HttpApi.Host/RealIpMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ public RealIpMiddleware(RequestDelegate requestDelegate, IOptions<RealIpOptions>

public async Task Invoke(HttpContext context)
{
var headers = context.Request.Headers;
if (!headers.ContainsKey(_realIpOptions.HeaderKey))
{
throw new ExternalException("Unknown ip address. no setting");
}

var ipArr = headers["X-Forwarded-For"].ToString().Split(',');
if (ipArr.Length == 0)
{
_logger.LogDebug("Unknown ip address");
throw new ExternalException("Unknown ip address. Refused visit server.ipArr is null");
}
#if DEBUG
if (ipArr.Contains(LocalIpaddress))
{
await _requestDelegate(context);
return;
}
#endif
_logger.LogDebug("Received IpList is :{ipList}", headers["X-Forwarded-For"]);
var ipList = ipArr.Select(ip => ip.Trim()).ToList();
_logger.LogInformation("ipList count {count} :",ipList.Count);
var caServerAddressIp = await _accountAppService.WhiteListCheckAsync(ipList);
_logger.LogInformation("caServerAddressIp is {0}",caServerAddressIp);
if (string.IsNullOrEmpty(caServerAddressIp))
{
_logger.LogDebug($"Resolve real ip is not in whiteList,Please check and retry.");
throw new ExternalException("Resolve real ip is not in whiteList,Please check and retry.");
}
// var headers = context.Request.Headers;
// if (!headers.ContainsKey(_realIpOptions.HeaderKey))
// {
// throw new ExternalException("Unknown ip address. no setting");
// }
//
// var ipArr = headers["X-Forwarded-For"].ToString().Split(',');
// if (ipArr.Length == 0)
// {
// _logger.LogDebug("Unknown ip address");
// throw new ExternalException("Unknown ip address. Refused visit server.ipArr is null");
// }
// #if DEBUG
// if (ipArr.Contains(LocalIpaddress))
// {
// await _requestDelegate(context);
// return;
// }
// #endif
// _logger.LogDebug("Received IpList is :{ipList}", headers["X-Forwarded-For"]);
// var ipList = ipArr.Select(ip => ip.Trim()).ToList();
// _logger.LogInformation("ipList count {count} :",ipList.Count);
// var caServerAddressIp = await _accountAppService.WhiteListCheckAsync(ipList);
// _logger.LogInformation("caServerAddressIp is {0}",caServerAddressIp);
// if (string.IsNullOrEmpty(caServerAddressIp))
// {
// _logger.LogDebug($"Resolve real ip is not in whiteList,Please check and retry.");
// throw new ExternalException("Resolve real ip is not in whiteList,Please check and retry.");
// }
await _requestDelegate(context);
}
}

0 comments on commit beeed16

Please sign in to comment.