Skip to content

Commit

Permalink
优化获取真实ip、增加pulsar支持
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyl1992 committed Jul 21, 2023
1 parent 3211d70 commit 7be680f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<NetProZeroMQ>6.0.15</NetProZeroMQ>
<NetProZeroMQAssemblyName>NetPro.ZeroMQ</NetProZeroMQAssemblyName>

<NetProPulsar>6.0.15</NetProPulsar>
<NetProPulsarAssemblyName>NetPro.Pulsar</NetProPulsarAssemblyName>

<NetProDependency>6.0.15</NetProDependency>
<NetProDependencyAssemblyName>NetPro.Dependency</NetProDependencyAssemblyName>

Expand Down
30 changes: 24 additions & 6 deletions src/Library/NetPro.Pulsar/NetPro.Pulsar.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(TargetsVersion)</TargetFrameworks>
<Version>$(NetProPulsar)</Version>
<Description>
</Description>
<AssemblyName>$(NetProPulsarAssemblyName)</AssemblyName>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageProjectUrl>https://github.com/LeonKou/NetPro/tree/dev_6.0/src/Library/NetPro.Pulsar</PackageProjectUrl>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\$(NetCoreTargetVersion)\NetPro.Pulsar.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\$(NetCoreTargetVersion)\NetPro.Pulsar.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="$(PackageIconPath)">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Include="readme.md" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
Expand Down
21 changes: 21 additions & 0 deletions src/Library/NetPro.Pulsar/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

## NetPro.Pulsar使用


### 使用
[![NuGet](https://img.shields.io/nuget/v/NetPro.Pulsar.svg)](https://nuget.org/packages/NetPro.Pulsar)

#### 初始化Pulsar服务(代码方式)
```csharp
public void ConfigureServices(IServiceCollection services, IConfiguration configuration = null, ITypeFinder typeFinder = null)
{
//pulsar注入
services.AddPulsarClient(configuration);
}
```

json待补充
```json

```

14 changes: 7 additions & 7 deletions src/Library/NetPro.Web.Api/Helper/WebHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,8 @@ public virtual string GetCurrentIpAddress()
{
//first try to get IP address from the forwarded header
if (_httpContextAccessor.HttpContext.Request.Headers != null)
{
if (_httpContextAccessor.HttpContext.Request.Headers.ContainsKey("X-Real-IP"))
{
stringIp = _httpContextAccessor.HttpContext.Request.Headers["X-Real-IP"];
return stringIp;
}
else if (_httpContextAccessor.HttpContext.Request.Headers.ContainsKey("X-Forwarded-For"))
{
if (_httpContextAccessor.HttpContext.Request.Headers.ContainsKey("X-Forwarded-For"))
{
stringIp = _httpContextAccessor.HttpContext.Request.Headers["X-Forwarded-For"];
if (!string.IsNullOrEmpty(stringIp))
Expand All @@ -146,6 +141,11 @@ public virtual string GetCurrentIpAddress()
}
return stringIp;
}
else if (_httpContextAccessor.HttpContext.Request.Headers.ContainsKey("X-Real-IP"))
{
stringIp = _httpContextAccessor.HttpContext.Request.Headers["X-Real-IP"];
return stringIp;
}
else
{
stringIp = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
Expand Down

0 comments on commit 7be680f

Please sign in to comment.