ALPN

Supported by

 

  TsgcWebSocketServer

  TsgcWebSocketHTTPServer

  TsgcWebSocketClient

 

*Requires custom Indy version.

 

Application-Layer Protocol Negotiation (ALPN) is a Transport Layer Security (TLS) extension for application-layer protocol negotiation. ALPN allows the application layer to negotiate which protocol should be performed over a secure connection in a manner that avoids additional round trips and which is independent of the application-layer protocols. It is needed by secure HTTP/2 connections, which improves the compresslion of web pages and reduces their latency compared to HTTP/1.x.

 

Client

You can configure in TLSOptions.ALPNProtocols, which protocols are supported by client. When client connects to server, these protocols are sent on the initial TLS handshake 'Client Hello', and it lists the protocols that the client supports, and server select which protocol will be used, if any.

 

You can get which protocol has been selected by server accessing to ALPNProtocol property of TsgcWSConnectionClient.

 

Server

When there is a new TLS connection, OnSSLALPNSelect event is called, here you can access to a list of protocols which are supported by client and server can select which of them is supported.

 

 

If there is no support for any protocol, aProtocol can be left empty.

 


// Client
procedure OnClientConnect(Connection: TsgcWSConnection);
var
  vProtocol: string;
begin
  vProtocol := TsgcWSConnectionClient(Connection).ALPNProtocol;
end;
 
// Server
procedure OnSSLALPNSelect(Sender: TObject; aProtocols: TStringList; var aProtocol: string);
var
  i: integer;
begin
  for i := 0 to aProtocols.count - 1 do
  begin 
    if aProtocols[i] = 'h2' then
    begin
      aProtocol := 'h2';
      break;
    end;
  end;
end;