Redirect HTTP to HTTPS TWebModule Delphi

635 Views Asked by At

I have the Delphi Web service, using TWebModule.. But, i have problem with HTTP/HTPPS. I can't redirect request http to https.

Can you help me?

1

There are 1 best solutions below

0
Admiral 13 On

It's very easy. In WebModuleUnit type the following:

procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
    Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  if Request.QueryFields.Values['proto'] = 'http' then
    if Request.QueryFields.Values['target'] <> '' then
      Response.SendRedirect('https://' + Request.QueryFields.Values['target'])
    else
      Response.Content := '<HTML><BODY>Invalid URI</BODY></HTML>';
  Response.Content :=
    '<html>' +
    '<head><title>DataSnap Server</title></head>' +
    '<body>DataSnap Server</body>' +
    '</html>';
end;