File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 11
22#region <USINGs>
33
4+ using System . Net ;
45using System . Threading . Tasks ;
56using Microsoft . Owin ;
67using Owin ;
@@ -21,7 +22,7 @@ public class JwsIntegration : OwinMiddleware
2122 /// <summary>
2223 /// 下一个“中间件”对象
2324 /// </summary>
24- OwinMiddleware _next ;
25+ readonly OwinMiddleware _next ;
2526
2627 /// <summary>
2728 /// 构造函数,第一个参数必须为 OwinMiddleware对象
@@ -49,16 +50,17 @@ public override Task Invoke(IOwinContext owinContext)
4950 if ( headers != null && headers . ContainsKey ( "X-Original-For" ) )
5051 {
5152 var ipaddAdndPort = headers [ "X-Original-For" ] ;
52- var dot = ipaddAdndPort . IndexOf ( ":" ) ;
53+ var colon = ipaddAdndPort . LastIndexOf ( ":" ) ;
5354 var ip = ipaddAdndPort ;
5455 var port = 0 ;
55- if ( dot > 0 )
56+
57+ if ( colon > 0 )
5658 {
57- ip = ipaddAdndPort . Substring ( 0 , dot ) ;
58- port = int . Parse ( ipaddAdndPort . Substring ( dot + 1 ) ) ;
59+ ip = ipaddAdndPort . Substring ( 0 , colon ) . Trim ( new [ ] { '[' , ']' , ' \x20 ' } ) ;
60+ port = int . Parse ( ipaddAdndPort . Substring ( colon + 1 ) ) ;
5961 }
6062
61- owinContext . Request . RemoteIpAddress = System . Net . IPAddress . Parse ( ip ) . ToString ( ) ;
63+ owinContext . Request . RemoteIpAddress = IPAddress . Parse ( ip ) . ToString ( ) ;
6264 if ( port != 0 ) owinContext . Request . RemotePort = port ;
6365 }
6466
You can’t perform that action at this time.
0 commit comments