#1 2025-03-17 18:36:57

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 547

How Get RemoteIP correctly ?

Hi Arnaud,

i try to get RemoteIP in MVC Server.
I set RemoteIPServer either to X-Real-IP or X-Forwarded-For.

But how can i access/Request RemoteIP from function in MVC-Server ?

i tried it this way:

function TMyMVCApplication.GetCallerIPAdresse: RawUtf8;
begin
  Result := FindIniNameValue(pointer(ServiceRunningContext.Request.Call.InHead), 'REMOTEIP: ');
  if Length(Result) = 0 then
    Result := ServiceRunningContext.Request.Call.LowLevelRemoteIP;
  if Length(Result) = 0 then
    Result := '127.0.0.1';
end;

But RemoteIP is empty

Thank you


Rad Studio 12.3 Athens

Offline

#2 2025-03-17 18:56:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,965
Website

Re: How Get RemoteIP correctly ?

My guess is that there is something wrong in the RemoteIPHeader value process.
I will investigate.
Edit: There was a bug: https://github.com/synopse/mORMot2/commit/40333d514

Try to debug THttpServerGeneric.ParseRemoteIPConnID() to see why the proxy header is not found.

Also note that FindNameValue() is preferred to FindIniNameValue() for parsing HTTP headers.

Offline

Board footer

Powered by FluxBB