both HTTP and HTTPS in same IW service app?

<< Click to Display Table of Contents >>

Navigation:  Forum >

both HTTP and HTTPS in same IW service app?

Forum link

 

 

 


 

01-17-2024, 12:04 AM:

 

Hi all-

 

Quick question, I think the answer is Yes, but I just wanted to confirm...

 

Can one single IW application (service) support both HTTP and HTTPS ?

 

(Im using http.sys, not OpenSSL)

 

Thanks.

 

 

 


 

01-19-2024, 12:39 AM:

 

Hoping I could get a response on this from AToZed ...

 

Thank You.

 

 

 


 

01-19-2024, 09:48 AM:

 

Hi,

 

Not the answer from Atozed but still usable I hope smile. Yes, this is possible.

 

One way is to use the TIWServerController.OnBind event.

 

Code:

 

procedure TIWServerController.IWServerControllerBaseBind(const aHttpBindings, aHttpsBindings: TStrings);

 

begin

 

  aHttpBindings.Clear;

 

  aHttpsBindings.Clear;

 

  {$IFDEF DEBUG}

 

    aHttpBindings.Add('http://*:80/');

 

  {$ELSE}

 

    aHttpBindings.Add('http://example.com:80/');

 

    aHttpBindings.Add('http://www.example.com:80/');

 

    aHttpsBindings.Add('https://example.com:443/');

 

    aHttpsBindings.Add('https://www.example.com:443/');

 

  {$ENDIF}

 

end;

 

 

 

For https make sure SSLOptions.Port is set like for Indy servers.

 

 

 


 

01-19-2024, 07:36 PM:

 

Yes, it is possible (and quite common) but it is the same application running both as HTTPS and HTTP.

 

@Jeroen's answer is correct, but there is no need to have custom code to make both bindings.... ServerController.SSLOptions.Port is also used to configure Http.sys servers.

 

In this case, you just need to set:

 

Code:

 

ServerController.Port := (your HTTP port, default is 80)

 

ServerController.SSLOptions.Port := (your HTTPS port, default is 443)

 

 

 

What will determine the behavior of the application is the property

 

ServerController.SSLOptions.NonSSLRequest

 

It can be either: nsAccept (default), nsRedirect and nsBlock

 

nsAccept: incoming requests using HTTP port will be accepted and everything will run using HTTP only protocol

 

nsRedirect: any incoming request using HTTP port will be redirected to HTTPS port (if HTTPS is enabled, i.e. you have ServerController.SSLOptions.Port > 0)

 

nsBlock: any incomping request using HTTP port will be blocked. In this case the HTTP server won't even listen to the HTTP. No response for HTTP request will be generated.

 

You can also have forms that are only accessible via HTTPS or HTTP and others that are accessibla via both protocols. In that case you need to use the property

 

IWForm.ConnectionMode

 

It can be either: 

 

cmAny (default): HTTP and HTTPS are accepted

 

cmSecure: Form will only accept HTTPS

 

cmNonSecure: Form will only accept HTTP

 

 

 


 

01-19-2024, 07:54 PM:

 

Perfect, thanks, I look forward to trying this.  smile

 

CW