#1 2026-05-05 16:59:19

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 52

RemoteIP for client is Empty.

Hello people.
I have a situation where I need to get the remote IP client connected to mORMot Http server, so in one function of the interface published I have this code.

{--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------}
function HttpFindHeaderValue(const Atext: String; const Atofind: String): String;
var
  I: Integer;
  Lipos: Integer;

begin
  Result := EmptyStr;
  // This test is returned when I use the browser for debug.
  //Host: 172.16.111.254:7443 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Upgrade-Insecure-Requests: 1
  //X-Forwarded-Proto: http X-Forwarded-For: 172.16.110.50 X-Host: 172.16.111.254:7443 X-Forwarded-Host: 172.16.111.254:7443

  Lipos := Pos(Atofind, Atext);

  if (Lipos <> -1) then
  begin

    Lipos := Lipos + Length(Atofind);
    I := Lipos;
    While (Atext[I] <>  #9) and
          (Atext[I] <> #10) and
          (Atext[I] <> #13)
    do
    begin
      Result := Trim(Result + Atext[I]);
      Inc(I);
    end;

  end;


end;


begin
  //LIp := SynCommons.FindIniNameValue(Pointer(ServiceContext.Request.Call.InHead), PAnsiChar('X-Forwarded-For: ')); // Not working it return '' (Empty string)
  LIp := HttpFindHeaderValue(ServiceContext.Request.Call^.InHead, 'X-Forwarded-For: ');  // this works
  Result := TLogin._Login(A, LIp);

The mORMot "SynCommons.FindIniNameValue" do not work for me.
PS:
   HttpServer in mORMot 1 trunk.
   Lighttpd as Proxy
   Lazarus/FPC
   SQLite.
So, I report this in case it is a bug or I miss something, but my code is working.

Offline

#2 2026-05-05 17:10:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,475
Website

Re: RemoteIP for client is Empty.

FindIniNameValue() needs the 2nd parameter in UPPERCASE - as it is named UpperName and documented as such.

But easier is to just set THttpSeverGeneric.RemoteIPHeader := 'X-Forwarded-For';
Then it will be set to Ctxt.RemoteIP

And it is time to switch to mORMot 2 if you can.

Offline

#3 2026-05-05 18:52:40

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 52

Re: RemoteIP for client is Empty.

It works smile, Thanks.
I'll try to see the impact before migrating to mORMot2.

Last edited by Bsaidus (2026-05-05 18:52:54)

Offline

#4 2026-05-05 19:08:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,475
Website

Re: RemoteIP for client is Empty.

Most mORMot users did the shift with not much suffering, I was told.

Offline

Board footer

Powered by FluxBB