You are not logged in.
Pages: 1
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
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
It works
, Thanks.
I'll try to see the impact before migrating to mORMot2.
Last edited by Bsaidus (2026-05-05 18:52:54)
Offline
Pages: 1