Servidor HTTP/2

Sirve HTTP/2 (h2) junto a HTTP/1.1 y WebSocket en un mismo puerto TLS mediante TsgcWebSocketHTTPServer. La negociación ALPN, HPACK y la multiplexación de streams están integradas.

TsgcWebSocketHTTPServer

El mismo TsgcWebSocketHTTPServer que se usa para WebSocket y HTTP/1.1 también sirve HTTP/2 sobre TLS — activa Specifications.HTTP2, ALPN se encarga del resto.

Clase del componente

TsgcWebSocketHTTPServer

Protocolo

HTTP/2 (RFC 9113)

Plataformas

Windows, macOS, Linux, iOS, Android

Edición

Professional / Enterprise

Activa HTTP/2 con una sola propiedad

En una instancia de TsgcWebSocketHTTPServer, activa TLS y conmuta Specifications.HTTP2 — la negociación ALPN h2 gestiona el upgrade automáticamente.

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;

Qué incluye

TsgcWebSocketHTTPServer con HTTP/2 habilitado — comparte un único endpoint TLS entre HTTP/1.1, HTTP/2 y WebSocket.

Negociación ALPN

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.

Coexistencia con WebSocket

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

HPACK + framing de streams

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.

Métricas de conexión

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

Especificaciones y referencias

Fuentes autorizadas del protocolo que implementa este componente.

Documentación y Demos

Enlace directo a la referencia del componente, descarga el proyecto demo listo para ejecutar y la prueba gratuita.

Ayuda en línea — TsgcWebSocketHTTPServer Referencia completa de propiedades, métodos y eventos de este componente.
Proyecto demo — Demos\20.HTTP_Protocol\01.HTTP2_Server_And_Client Proyecto de ejemplo listo para ejecutar. Se incluye en el paquete sgcWebSockets — descarga la prueba gratuita más abajo.
Documento técnico (PDF) Características, inicio rápido, ejemplos de código para Delphi y C++ Builder y referencias de fuentes primarias — solo este componente.
Manual de usuario (PDF) Manual completo que cubre todos los componentes de la biblioteca.

¿Listo para servir HTTP/2 desde Delphi?

Descarga la prueba gratuita y sirve HTTP/1.1, HTTP/2 y WebSocket desde un único endpoint TLS.