HTTP/2 Server

Serve HTTP/2 (h2) alongside HTTP/1.1 and WebSocket on a single TLS port via TsgcWebSocketHTTPServer. ALPN negotiation, HPACK and stream multiplexing are built in.

TsgcWebSocketHTTPServer

The same TsgcWebSocketHTTPServer used for WebSocket and HTTP/1.1 also serves HTTP/2 over TLS — toggle Specifications.HTTP2, ALPN handles the rest.

Component class

TsgcWebSocketHTTPServer

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Professional / Enterprise

Enable HTTP/2 with one property

On a TsgcWebSocketHTTPServer instance, enable TLS and toggle Specifications.HTTP2 — ALPN h2 negotiation handles the upgrade automatically.

uses
  sgcWebSocket;

var
  Server: TsgcWebSocketHTTPServer;
begin
  Server := TsgcWebSocketHTTPServer.Create(nil);
  Server.Port := 443;
  Server.SSL  := True;
  Server.SSLOptions.CertFile := 'cert.pem';
  Server.SSLOptions.KeyFile  := 'key.pem';

  // Allow HTTP/1.1, HTTP/2 and WebSocket on the same port
  Server.Specifications.HTTP   := True;
  Server.Specifications.HTTP2  := True;
  Server.Specifications.RFC6455 := True;

  Server.OnCommandGet := procedure(AContext: TIdContext;
    ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo)
  begin
    AResponseInfo.ContentText := 'Hello over HTTP/' + IfThen(ARequestInfo.HTTP2, '2', '1.1');
  end;

  Server.Active := True;
end;
// uses: sgcWebSocket
TsgcWebSocketHTTPServer *Server = new TsgcWebSocketHTTPServer(this);
Server->Port = 443;
Server->SSL  = true;
Server->Specifications->HTTP2 = true;
Server->Active = true;

What's inside

TsgcWebSocketHTTPServer with HTTP/2 enabled — share one TLS endpoint between HTTP/1.1, HTTP/2 and WebSocket.

ALPN negotiation

During the TLS handshake the server advertises both http/1.1 and h2. The client picks the protocol; the server dispatches accordingly — no separate listening socket needed.

WebSocket coexistence

WebSocket clients still upgrade through the HTTP/1.1 path. RFC 8441 (Bootstrapping WebSockets with HTTP/2) is supported via Specifications.RFC8441.

HPACK + stream framing

Built-in HPACK encoder for response headers and a stream-multiplexing core that dispatches each request on its own stream-id, with priority hints respected.

Server push

Server push (PUSH_PROMISE) is supported but is now deprecated — modern clients ignore it; consider 103 Early Hints or HTTP/3 for hints instead.

TLS choice

Set SSLOptions.IOHandler to iohOpenSSL (cross-platform) or iohSChannel (Windows). HTTP/2 requires TLS 1.2+ as per RFC 7540 / 9113 deployment.

Connection metrics

Each HTTP/2 connection exposes stream count, RTT estimates, total bytes in/out and the negotiated SETTINGS frame parameters via OnHTTP2Settings.

Specifications & references

Authoritative sources for the protocol this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — TsgcWebSocketHTTPServer Full property, method and event reference for this component.
Demo Project — Demos\20.HTTP_Protocol\01.HTTP2_Server_And_Client Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Serve HTTP/2 from Delphi?

Download the free trial and serve HTTP/1.1, HTTP/2 and WebSocket from a single TLS endpoint.