File tree 1 file changed +13
-5
lines changed
1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -187,11 +187,19 @@ public static void Main(string[] args)
187
187
{
188
188
app . MapGet ( "/api/Bootstrap/publicip" , async ( HttpContext context ) =>
189
189
{
190
- var headers = context . Request . Headers . ToDictionary ( h => h . Key , h => h . Value . ToString ( ) ) ;
191
- return Results . Text ( headers . ToString ( ) ) ;
192
-
193
- string ip = context . Connection . RemoteIpAddress ? . ToString ( ) ?? "Unknown" ;
194
- return Results . Text ( ip , "text/plain" ) ;
190
+ var forwardedFor = context . Request . Headers [ "X-Forwarded-For" ] . ToString ( ) ;
191
+ string clientIp = string . Empty ;
192
+
193
+ if ( ! string . IsNullOrEmpty ( forwardedFor ) )
194
+ {
195
+ clientIp = forwardedFor . Split ( ',' ) . First ( ) . Trim ( ) ;
196
+ }
197
+ else
198
+ {
199
+ clientIp = context . Connection . RemoteIpAddress ? . ToString ( ) ?? "Unknown" ;
200
+ }
201
+ string result = $ "Header: X-Forwarded-For | Value: { forwardedFor } | ClientIP: { clientIp } ";
202
+ return Results . Text ( result , "text/plain" ) ;
195
203
} ) ;
196
204
}
197
205
You can’t perform that action at this time.
0 commit comments