Jonathan Wareham
Jonathan Wareham

Reputation: 3397

DataSnap Server - Send custom HTTP response headers

I have built a standalone (Delphi EXE) DataSnap server using TDSServer, TDSServerClass etc. I want to be able to send custom HTTP headers in the response from my server methods. I can see I can use GetInvocationMetadata() to customise the response status code, message, content and the Content-Type header, but can't see any way of adding my own response headers. Is this possible?

Upvotes: 1

Views: 1004

Answers (1)

Roberto Novakosky
Roberto Novakosky

Reputation: 371

Example:

function TControllerAplicacao.EchoString(Value: string): string;
var
 objWebModule: TWebModule; //need Web.HTTPApp
begin
  //the Solution
  objWebModule := GetDataSnapWebModule; //need Datasnap.DSHTTPWebBroker
  objWebModule.Response.SetCustomHeader('MY-CUSTOM-HEADER','ABCD12324');
  //do the test using postman, and see on HEADERS

 Result := Value; //from original datasnap example EchoString

end;

Upvotes: 2

Related Questions