danieleteti / wchttpserver

HTTP/2+HTTP/1.1+WebSocket server written with Lazarus (Free Pascal)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

alt text

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:

  1. There are two server modes of operation, optimized for REST and RPC architectures.
  2. Client management using cookies (saving and maintaining sessions).
  3. Saving information about clients and sessions in SQLite database.
  4. Saving information about the latest requests and saving logs in SQLite database.
  5. Multithreading preparation and execution of requests based on threads pools e.g. helpful classes to work with EventSources.
  6. Clients ranking based on clients frequency of requests.
  7. Built-in support for gzip and deflate compression methods including decompression of client-side requests.
  8. The WebSocket (RFC 6455) protocol is supported with the "permessage-deflate" extension (RFC 7692).
  9. Ability to start the server both in HTTP/2 (RFC 7540) mode and in HTTP/1.1 mode.
  10. Modified OpenSSL modules (added necessary TLS extensions) to create and maintain HTTP/2 connections.
  11. 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).
  12. 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

  1. SQLite
  2. OpenSSL (v1.1.0 or higher)
  3. Zlib
  4. CommonUtils - you can download sources here

Copyrights

About

HTTP/2+HTTP/1.1+WebSocket server written with Lazarus (Free Pascal)

License:GNU Lesser General Public License v2.1


Languages

Language:Pascal 100.0%