Show/Hide Toolbars

TMS Sparkle Documentation

Navigation: Http Server

Http.Sys-based Server

Scroll Prev Top Next More

For servers running on Windows platform, Sparkle provides an HTTP server based on Microsoft HTTP Server API, which is an interface for the HTTP protocol stack (HTTP.sys). This makes Sparkle HTTP Server a full-featured, robust and fast server on Microsoft Windows. Many operations like routing HTTP requests, caching of responses, encryption and authentication runs in kernel-mode. It's the same stack used by Microsoft IIS.

 

It plays the role of the "HTTP Server" as described in the overview of Sparkle server architecture. It's a Delphi class that is a layer over the Microsoft API, receive the requests from operational system, and dispatch the requests to the proper server modules.

 

The following code illustrates how to create the server, add modules and start it.

 

uses {...}, Sparkle.HttpSys.Server;
 
var
  Server: THttpSysServer;
begin
  Server := THttpSysServer.Create;
  Server.Dispatcher.AddModule(TMyServerModule.Create('http://host:2001/myapplication');
  Server.Dispatcher.AddModule(TAnotherModule.Create('http://+:2001/anotherapp');
  Server.Start;
  
  // server runs in console mode until user hits Return
  ReadLn;
 
  Server.Stop;
end;

 

In the example above, any request to URIs beginning with "http://server.com/myapplication" will be dispatched to TMyServerModule. And any requests to address "http://host:2001/" will be dispatched to TAnotherModule.

 

By default, Sparkle will strip the host part of the url and replace with a + symbol. So even in the first example with "host" as the server, internally it will change to +:2001. This is desired for most cases. If you want Sparkle to keep the host name (for example, if you are listening to different IP address/host names in the same server, then you can set KeepHostInUrlPrefixes property to true:

 

Server.KeepHostInUrlPrefixes := True;

 

Since THttpSysServer is based on the http.sys stack, the URI you want to listen (like the "http://+:2001/" in example) must be reserved in the Windows. Otherwise your application won't be able to respond to such requests. This is not Sparkle-related, but all requirements on the http.sys itself. There is plenty documentation over the internet about how to reserve and configure many details of the server, like configuring server-side certificates, for example. However, Sparkle also provides helpful tools for you to accomplish these tasks. The following topics will try to summarize the basic steps you need to perform such operations and how Sparkle can help you out with it.

 

URL namespace and reservation

Using HTTP secure (HTTPS)

TMSHttpConfig Tool

THttpSysServerConfig Class

Windows netsh Command-Line