One HTTPS server in Modern Pascal to Rule Them All

ArnaudBouchez1 20 views 76 slides Oct 29, 2025
Slide 1
Slide 1 of 76
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76

About This Presentation

A brand new asynchronous and event-driven HTTP server was written for mORMot 2, and we added some general-purpose features to make it a potential alternative to apache, nginx, caddy or IIS. We will present this web server, and some of its features.

Hands-On

Use modern object pascal for HTTP se...


Slide Content

One HTTPS Server
in Modern Pascal
to Rule Them All
When embedded is better

Welcome
Arnaud Bouchez
•Open Source Founder
• mORMot 1, mORMot 2, SynPDF, dmustache
•Modern Object Pascal
Delphi and FPC -Embarcadero MVP
•Synopse Tranquil IT
https://synopse.info https://tranquil.it

Welcome
Arnaud Bouchez
•Open Source Founder
• mORMot 1, mORMot 2, SynPDF, dmustache
•Modern Object Pascal
Delphi and FPC -Embarcadero MVP
•Synopse Tranquil IT
https://synopse.info https://tranquil.it

One HTTPS Server
in Modern Pascal
to Rule Them All

Hands On
•Serve HTTPS from modern Object Pascal
•Web server best practices
•Beyond Apache, Nginx, Caddy or IIS
•Integrate the mORMot 2 Web Server
•Optionally leverage its Toolbox

Today’s Special
•HTTPS Web Servers
•mORMot 2 THttpAsyncServer
•ACME, PeerCache, ProxyCache
•Usecasesfor your projects

Today’s Special
•HTTPS Web Servers
•mORMot 2 THttpAsyncServer
•ACME, PeerCache, ProxyCache
•Usecasesfor your projects

HTTPS Web Servers

HTTPS Web Servers
Apache, Nginx, Caddy, IIS…
•Resolve Host names
•Serve static content
•Forward dynamic content
•Handle HTTPS security

HTTPS Web Servers
Apache, Nginx, Caddy, IIS…

HTTPS Web Servers
•HTTPS via ACME services
•HTTPS is mandatory
•Enter the Trust Chain
•Paid or free certificate
•Periodic renewal

HTTPS Web Servers
HTTPS via ACME services

HTTPS Web Servers
IIS–Internet Information Services
•Windows Specific
•Based on http.sys system driver
•Use the system registry and netshtool

HTTPS Web Servers
Apache, Nginx, Caddy
•Use configuration files
•Favor Linux/BSD
•Well known

HTTPS Web Servers
Apache
•The venerable web server
•LAMP (Linux Apache MySQLPHP)
•WAMP for debugging/testing
•Somewhat old and not scaling

HTTPS Web Servers
Nginx
•The most used in the Internet
•Very fast
•Unusable on Windows

HTTPS Web Servers
Caddy
•Written in Go
•Built-in HTTPS / ACME
•Convenient, but not as fast

HTTPS Web Servers
Apache, Nginx, Caddy, IIS…
•Another brick in the project
•Part of the Operating System
•System wide configuration
•HTTPS may be tricky to get working
•Can be tampered (for good or evil)

Today’s Special
•HTTPS Web Servers
•mORMot 2 THttpAsyncServer
•ACME, PeerCache, ProxyCache
•Usecasesfor your projects

mORMot 2 THttpAsyncServer

mORMot 2 THttpAsyncServer
•mormot.net.async.pas
•mormot.net.server.pas
•mormot.net.http.pas
•mormot.net.sock.pas

mORMot 2 THttpAsyncServer
mormot.net.sock.pas
•Cross-platform and cross-compiler
•High-level Socket abstraction
•poll() or epoll() API on POSIX/Linux
•IOCP on Windows(via mormot.core.os)
•INetTlsabstraction for HTTPS

mORMot 2 THttpAsyncServer
INetTlsabstraction for HTTPS
•OpenSSLon POSIX and Windows
mormot.lib.openssl11.pas
•SSPI / SChannelAPI on Windows
mormot.net.sock.pas

mORMot 2 THttpAsyncServer
mormot.net.http.pas
•Fast client/server HTTP state machine
•THttpServerRequestAbstractclass
•Logging/Metrics/IPBanengines

mORMot 2 THttpAsyncServer
mormot.net.server.pas
•Efficient URI routing
•THttpServerGenericclass
•THttpServerclass (not async)
•THttpApiServer(http.sys -Windows only)
•THttpPeerCache

mORMot 2 THttpAsyncServer
mormot.net.async.pas
•Non-blocking socket connections
•THttpAsyncServerEvent-Driven server
•THttpProxyServerwith cache

mORMot 2 THttpAsyncServer
mormot.net.async.pas
•Non-blocking socket connections
•THttpAsyncServerEvent-Driven server
•THttpProxyServerwith cache

mORMot 2 THttpAsyncServer
THttpAsyncServerEvent-Driven
•IOCP on Windows, epoll() on Linux
•Non-blocking socket+httpstate engine
•Internal thread pool
•Minimize memory allocations and locks

mORMot 2 THttpAsyncServer
THttpAsyncServerEvent-Driven
•Leverage simple/cheap hardware
•e.g. #1 in the TFB challenge
for serving cached ORM JSON
•Cross-platform and cross-compiler

mORMot 2 THttpAsyncServer
THttpServerGeneric.Router
•Register GET/POST/PUT… URIs
•Rewrite URIs in-place
•Redirect to Object Pascal callbacks

mORMot 2 THttpAsyncServer
THttpServerGeneric.Router
•Register GET/POST/PUT… URIs
•Rewrite URIs in-place
•Redirect to Object Pascal callbacks
… so you can do whatever you want …
… in pure code, with no configfiles …

mORMot 2 THttpAsyncServer
function TMyServer.Cached(ctxt: THttpServerRequest): cardinal;
vari: integer;
res: TOrmWorlds;
begin
SetLength(res, GetQueriesParamValue(ctxt, 'COUNT='));
for i:= 0 to length(res) -1 do
res[i] := fRawCache[Random32(WORLD_COUNT)];
result := ctxt.SetOutJson(@res, TypeInfo(TOrmWorlds));
end;

mORMot 2 THttpAsyncServer
https://www.techempower.com/benchmarks/#section=data -r23&test=cached-query

mORMot 2 THttpAsyncServer
SHOW ME THE CODE !

mORMot 2 THttpAsyncServer
THttpServer.Options
= set of THttpServerOption;
Let’s look at mormot.net.server.pas

mORMot 2 THttpAsyncServer
THttpServerOption
•IncludeDateHeader
•Ban40xIP
•EnableLogging
•TelemetryCsv/Json
•RejectBotUserAgent…

mORMot 2 THttpAsyncServer
THttpServerSocketGeneric.Banned
•Access a THttpAcceptBanIPv4 banning list
•Via hsoBan40xIP option
or manually from your code

mORMot 2 THttpAsyncServer
THttpServerSocketGeneric.BlackListUri
:= 'https://www.spamhaus.org/drop/drop.txt';
or any CIDR text list address
•Reject unsafe IP ASAP
•Automated daily update/refresh

mORMot 2 THttpAsyncServer
THttpServerSocketGeneric.SetAuthorize*()
•Enable BASIC / DIGEST / NEGOTIATE
authorization schemes
•BASIC/DIGEST with efficient in-memory lookup
•NEGOTIATE on POSIX (GSSAPI)and Windows (SSPI)

mORMot 2 THttpAsyncServer
THttpServerSocketGeneric.KeyTab
•Allow server-side Kerberos authentication
•Using an external keytabfile on POSIX/GSSAPI
•Can serve content outside of a Domain

mORMot 2 THttpAsyncServer
TWebSocketAsyncServer
•In mormot.net.ws.async.pasunit
•Plain HTTP, but can upgrade to WebSockets
•Non-blocking WebSocketsserver via callbacks

mORMot 2 THttpAsyncServer
TWebSocketAsyncServer

mORMot 2 THttpAsyncServer
As used by TRestHttpServer
•To publish a mORMot TRestServerlogic
•Over HTTP or WebSockets
•High-level SOA via methods or interfaces
•MVC Web with Mustache templates
… but not mandatory -and not this session topic ;)

Today’s Special
•HTTPS Web Servers
•mORMot 2 THttpAsyncServer
•ACME, PeerCache, ProxyCache
•Usecasesfor your projects

ACME, PeerCache, ProxyCache
Some “advanced” features
•Needed for my current work at TranquilIT
•Mimics existing features in pure pascal
(Let’s Encrypt certbot, MS BranchCache, Nginx/Squid)

ACME, PeerCache, ProxyCache
Some “advanced” features
•Needed for my current work at TranquilIT
•Mimics existing features in pure pascal
(Let’s Encrypt certbot, MS BranchCache, Nginx/Squid)
… but may be handy for your projects too!

ACME client for HTTPS

ACME client for HTTPS
Let’s the mORMot keep your keys!

ACME client for HTTPS
TAcmeLetsEncryptServer
•From mormot.net.acme.pas
•Host a simple HTTP server on port 80
to fulfill Let’s Encrypt or ZeroSSLchallenges
•Renew the certificates when needed
•Interact e.g. with a regular THttpAsyncServer

ACME client for HTTPS
TAcmeLetsEncryptServer
•Use OpenSSLfor the TLS / HTTPS layer
•No other external script or library
•Sensitive self-configuration by default

Custom/Mutual HTTPS
Specify your own certificates
•No need of ACME if you own the client
•Generate certificates mormot.crypt.secure.pas
•Server certificates -and your own CA
•Client certificates –for mutual authentication

Peer Cache

Peer Cache
THttpPeerCache
•From mormot.net.server.pas
•Maintain a cache between network peers
of remote HTTP/HTTPS resources
•Secured with proper cryptography

Peer Cache
THttpPeerCache= class(IWGetAlternate)
Used by our WGET -but with
1) UDP broadcast on the local network
2) Download a resource locally if available
or in the original URI for the first peer
3) Other peers would reuse this download
if they need the same resource

Proxy Cache

Proxy Cache
THttpProxyServercaching proxy
•Encapsulate THttpAsyncServer
•Use in-memory or on-disk (JSON) settings

Proxy Cache
THttpProxyServerpurpose
•Serve static content with in-memory cache
•Proxy remote content with disk cache
•Routing to Object Pascal callbacks

Proxy Cache
THttpProxyServerpurpose
•Serve static content with in-memory cache
•Proxy remote content with disk cache
•Routing to Object Pascal callbacks

Proxy Cache
Proxy remote content with disk cache
•e.g. to cache apt/rpm repositories
or any HTTP/HTTPS resources
•Optional PeerCachesupport (soon)
•A single executable on Windows or POSIX

Proxy Cache
SHOW ME THE CODE !

Today’s Special
•HTTPS Web Servers
•mORMot 2 THttpAsyncServer
•ACME, PeerCache, ProxyCache
•Usecasesfor your projects

When to use the mORMot

When to use the mORMot
mORMot is not a framework
… but a Toolbox
•You can pickup what you need
•You can use its Web Server
without the REST, SOA, ORM, DB…

When to use the mORMot
If you need regular PHP hosting

When to use the mORMot
If you need regular PHP hosting
•Then Nginxmay be a better candidate
•With a reverse proxy
to a PHP engine or a mORMot server
for dynamic content

When to use the mORMot
If you need regular PHP hosting
•Then Nginxmay be a better candidate
•But stay tuned…
because we plan to host PHP
very soon 

When to use the mORMot
If you extend a project to the web

When to use the mORMot
If you extend a project to the web
•You have an existing Object Pascal code
•You need to publish it over REST
•With some static content

When to use the mORMot
If you extend a project to the web
•You have an existing Object Pascal code
•You are using Windows and Delphi
•But plan to support Linux and FPC

When to use the mORMot
If you extend a project to the web
•You know well Object Pascal
•You don’t know so well Nginx& co
•But need HTTPS support

When to use the mORMot
If you extend a project to web/REST
•And consider configfiles as unsafe
•Or favor single executable delivery
•Or want to automate your own CA
•Or need a turnkey solution (e.g. regulation)

When to use the mORMot
If you extend a project to web/REST
•You have an existing Object Pascal code
•You plan to support Linux and FPC
•You prefer Object Pascal to configfiles
Then look at the mORMot Web Server!

When to use the mORMot
Don’t forget you can mix both
•You could e.g. use Nginx
as reverse proxy over a mORMot server
•And disable e.g. mORMot ACME or cache
at runtime in such cases

Today’s Special
•HTTPS Web Servers
•mORMot 2 THttpAsyncServer
•ACME, PeerCache, ProxyCache
•Usecasesfor your projects

To Visit the marmots
https://cauterets.site

Questions?