wchttpserver
HTTP/2+HTTP/1.1+WebSocket server written with Lazarus (Free Pascal)
The project builds on fpWeb modules and extends them to increase functionality:
- There are two server modes of operation, optimized for REST and RPC architectures.
- Client management using cookies (saving and maintaining sessions).
- Saving information about clients and sessions in SQLite database.
- Saving information about the latest requests and saving logs in SQLite database.
- Multithreading preparation and execution of requests based on threads pools e.g. helpful classes to work with EventSources.
- Clients ranking based on clients frequency of requests.
- Built-in support for gzip and deflate compression methods including decompression of client-side requests.
- The WebSocket (RFC 6455) protocol is supported with the "permessage-deflate" extension (RFC 7692).
- Ability to start the server both in HTTP/2 (RFC 7540) mode and in HTTP/1.1 mode.
- Modified OpenSSL modules (added necessary TLS extensions) to create and maintain HTTP/2 connections.
- Added the ability to save the master key and a random set of client data on the server-side (necessary for debugging TLS dumps using WireShark).
- Working both under Windows and Linux.
What the project contains?
- Source files with abstract classes, structures, and commonly used utils.
- Demo - the HTTP/2 server (wchttpserverdemo.lpi, wchttpserverdemo.lpr, wctestclient.pas, wcservertestjobs.pas, wcmaintest.pas, server.cfg, sample site ./webclienttest/*).
- Examples - a number of examples of simple servers for specific tasks.
How to deal with the example?
- Build it using the necessary development environment and libraries or download precompiled release.
- Do not forget to generate a certificate and key file for your localhost (put them in ./openssl folder).
- Command-line to start testing server: "wchttpserver {PORTNUM} [-debug]" (PORTNUM - is a number of the listening port - 8080 for example)
How to write your own server?
- Rewrite wchttpserverdemo.lpr - write here locations for your own files (certificates, keys, mime file, site files, session database, log database, list of using ciphers, list of necessary protocols, initial values for http/2 headers, num of threads) or do it by editing external config file "server.cfg".
- Rewrite wcmaintest.pas - write here your own TWCPreAnalizeClientJob descendant class to implement the task which pre-analyzing requests and creating corresponding async tasks. Adwise you to using data trees like in example to realize such pre-analyzing task.
- Rewrite wctestclient.pas - implement here your own descendant class for TWebClient where add your own properties and functionality (just look how this is done in example file).
- Rewrite wcservertestjobs.pas - write your own server's async tasks here (descendant classes for TWCMainClientJob). Every task is connected to the requesting client.
- Add your own site files - scripts, pages, CSS, images, and so on in your site folder.
Development environment
Free Pascal (v3.2.0) + Lazarus (v2.0.10)
Necessary libraries
- SQLite
- OpenSSL (v1.1.0 or higher)
- Zlib
- CommonUtils - you can download sources here
Copyrights
- fcl-web (fpWeb) - part of Free Pascal's Free Component Library (FCL), focusing on web (related) application development
- Ararat Synapse - SSL support by OpenSSL - Copyright (c) 1999-2005, Lukas Gebauer
- Compact zlib, deflate, inflate, zip library in JavaScript
- CommonUtils - lightweight lists, collections, seqs and hashes, helping classes for sqlite3 extension, gz compression, data streams - Copyright (c) 2018-2021, Ilya Medvedkov
- WCHTTPServer - Copyright (c) 2020-2021, Ilya Medvedkov