#1 2013-05-23 12:24:26

DarekZ
Member
Registered: 2013-01-28
Posts: 3

THttpApiServer and SSL

Hi,
I am looking solution for encoding http transport using SSL method. I tried to editing TJSONServer (example no 13) unfortunately I don't know what I ought to do to enable SSL (...)
This is my sample code.

constructor TJSONServer.Create(Props: TSQLDBConnectionProperties);
var Conn: TSQLDBConnection;
begin
  try
    fServer := THttpApiServer.Create(false);
    fServer.AddUrl('root','8892', false, '+');
    fServer.AddUrlAuthorize('root2','8892', true, '+');
    fServer.RegisterCompress(CompressDeflate);
    fServer.OnRequest := Process;

  except
    on e:Exception do
     Write(e.Message);
  end;
end;

and simple request handler

function TJSONServer.Process(Ctxt: THttpServerRequest): cardinal;
begin
  try
    Ctxt.OutContentType := TEXT_CONTENT_TYPE_HEADER;
    Ctxt.OutContent := 'Aqq';
    result := 200;
  except
    on E: Exception do begin
      result := 500;
    end;
  end;
end;

I tried to call above urls from fiddler, so when I am sending request to
http://localhost:8892/root
I have response Aqq
but when I am sending request to http://localhost:8892/root2 or https://localhost:8892/root2 I have errors. 503 - HTTP Error 503. The service is unavailable for HTTP and 502 - The socket connection to localhost failed for HTTPS.


What is wrong? Is it possible to use SSL (with dynamic keys) in this case?

Regards

Last edited by DarekZ (2013-05-23 12:25:50)

Offline

#2 2013-05-23 12:59:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: THttpApiServer and SSL

fServer.AddUrlAuthorize('root2','8892', true, '+');

Does not publish the root2 url to the server.
It just add the root2:8892 url to the internal http.sys authorization list.

So you need to write:

fServer.AddUrl('root2','8892', true, '+');

to publish the server content on root2:8892.

I'm not sure you can share the same port for both http and https.

I did not test ssl access, but there was feedback about it in the forum.
For instance, http://synopse.info/forum/viewtopic.php?id=901

See also what DWS stated about that in https://code.google.com/p/dwscript/wiki/WSServerOptions
Perhaps we will need to update the http.sys API from current 1.0 to 2.0 revision (which seems to have direct SSL process).

In all cases, I suspect you need to follow the WCF guide to register the certificates - http://www.codeproject.com/Articles/240 … CF-Service
(mORMot and WCF share the same http.sys registering process)
Feedback is welcome!

Offline

Board footer

Powered by FluxBB