Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Request Header in Delphi XE3 DataSnap Server

I am implementing a REST server API in Delphi XE3 (first time using Delphi in about a decade so am a bit rusty). Currently it is using Indy server for debug purposes, but eventually it will be an ISAPI dll.

Now I have implemented a number of TDSServerClass classes and want to access the request header within the class methods. So for example when the user requests mysite.com/datasnap/rest/foo/bar I want to be able to read the header within the foo class method called bar. Is this possible?

If not, is it possible to create a global filter of incoming requests before they get to the REST class method? I need to check the API key and user authentication on incoming requests and not sure the best way to implement. Thanks.

like image 621
Joel Avatar asked Nov 04 '22 07:11

Joel


1 Answers

I don't know if anything changed in XE3, but in XE2 you can do the following:

uses
  Web.HTTPApp,
  Datasnap.DSHTTPWebBroker;

function TServerMethods1.EchoString(Value: string): string;
var
  Module: TWebModule;
begin
  Module := GetDataSnapWebModule;
  Result := Module.Request.RemoteIP + ': ' + Value;
end;
like image 196
Ondrej Kelle Avatar answered Nov 09 '22 03:11

Ondrej Kelle