Jump to content
mvanrijnen

marsRequest.RemoteIP empty when using ISAP, filled when using cmdline (indy)

Recommended Posts

My base class (partial):

 

In the following example, the RemoteIP is not filled when using ISAPI dll, running onder IIS

 

  TMyMars=class
  private
    FRequestID: string;
    FResourcePath: string;
    FRequestTimeStamp: TDateTime;
    FRequestIPSource: string;
    FMethodName: string;
  protected
    [Context] marsRequest: IMARSRequest;
    [Context] Response: IMARSResponse;
    [Context] Activation : IMARSActivation;
    procedure DumpJSON(const AFileNamePrefix, AJSON, AFolder : string; const APathSplit : TPathSplit);
  public
    constructor Create; virtual;

    [BeforeInvoke]
    procedure BeforeInvoke; virtual;
    [AfterInvoke]
    procedure AfterInvoke; virtual;

    [InvokeError]
    function ErrorHandler(const AException: Exception): Boolean; virtual;

    [Get, Path('ping'), Produces(TMediaType.APPLICATION_JSON)]
    function Ping(): TPingResult;

    property ResourceMethodName: string read FMethodName;
    property ResourcePath : string read FResourcePath;
    property RequestTimeStamp: TDateTime read FRequestTimeStamp;
    property RequestID:  string read FRequestID;
    property RequestIPSource: string read FRequestIPSource;
  end;
 

implementation:


procedure TMyMars.BeforeInvoke;
begin
  LogExDebug('RemoteIP: %s', [marsRequest.RemoteIP], 'TMyMars.BeforeInvoke');
  FResourcePath := Activation.ResourcePath;
  FRequestIPSource := marsRequest.RemoteIP;
  FMethodName := Activation.Method.Name;
end;

 

 

Edited by mvanrijnen

Share this post


Link to post

Does

marsRequest.RemoteIP

contain an empty string, or an unexpected value? And do the other fields of marsRequest contain sensible (non-default) values?

Edited by mjustin

Share this post


Link to post

hmz,

made a dump of the other values in the request:

 


Accept: */*
Authorization: 
Method: POST
QueryString: 
RawPath: /rest/default/MyWebhookReceiver/
Hostname: my.wscompany.eu
RemoteIP: 
UserAgent: PostmanRuntime/7.32.1


 

@Andrea Magni

Seems not everything is filled? Do i have to configure something for this to work ? in MARS or in IIS ?

 

 

 

Share this post


Link to post

Attached the debugger, here is where i come out:

 

Unit: Web.HTTPapp

 

function TWebRequest.GetRemoteIP: string;
begin
  Result := EmptyStr;
end;
 

 

explains a lot 🙂

how to fix?

 

 

[edit]

got a fix (needs to be double checked)

Replace RemoteIP in the FWebrequest to RemoteAddr.

 

Unit: MARS.http.Server.Indy:

 

Code:


function TMARSWebRequest.GetRemoteIP: string;
begin
//  Result := FWebRequest.RemoteIP;
  Result := FWebRequest.RemoteAddr;
end;

Edited by mvanrijnen

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×