API Reference
StreamSec.Mobile.HTTPS
HTTPS application-layer plugins for the async TLS - server: TsmHTTPSv1dot1 (+ TsmHTTPSv2 pending)
Feature notes: TLS implementation notes (RFC map)
Classes, interfaces and records
classtCustomHTTPLimits
inherits from TPersistent
THE BOUNDS THIS LAYER ENFORCES, ON THE OBJECT INSPECTOR - split by the wire they belong to, so a component only ever publishes bounds that actually do something on it. These were compile-time constants, which meant an operator who needed a 32 MiB upload limit, or who wanted to drop concurrent streams under attack, had to recompile the library - and it made the component the odd one out, since the async TLS server publishes its own capacities (MaxConcurrentHandshakes, MaxLiveSessions, the timeouts, MaxSendQueueBytes) exactly like this. The constants did not go away: each is still the default, so a component nobody configures behaves precisely as it did before. Published as a sub-object rather than as a dozen loose properties, matching TsmAsyncTLSServer.OcspOptions - the limits belong together and read as a group.
THIS BASE HOLDS ONLY WHAT BOTH WIRES ENFORCE. It is abstract in practice: a protocol component mints the right descendant from GetNewLimits and republishes it at that type, so TsmHTTPSv1dot1.Limits is a tHTTP11Limits and TsmHTTPSv2.Limits is a tHTTP2Limits, both statically.
0 MEANS UNBOUNDED on every bound in this family, and is a decision to be taken deliberately: each exists because something without it was a denial-of-service hole, and the comments say which. A negative normalises to 0 on the way in.
constructor Create(aOwner: TComponent); virtual;
procedure AssignTo(Dest: TPersistent); override;
Copies the bounds THIS class holds. Each descendant chains to it and then copies its own, so assigning across the two wire families copies exactly the bounds the two genuinely share - which is all that is meaningful. The published properties are typed, so that can only happen through an explicit Assign, never through the Object Inspector.
property BodyBytes: Integer read fBodyBytes write SetBodyBytes default cMaxBodyBytes;
BOTH wires. Largest assembled request body for ONE request. A request whose Content-Length is over it is answered 413 before any of its body is taken in, on both wires (on HTTP/2 followed by RST_STREAM(NO_ERROR)); an HTTP/2 body with no content-length is reset with ENHANCE_YOUR_CALM when it reach...
Full description »
property TotalBodyBytes: Int64 read fTotalBodyBytes write SetTotalBodyBytes;
BOTH wires, and the only bound here that is SERVER-wide: request bodies held across every connection this component serves.
Full description »
BOTH wires. Deadlines against a peer that sends a request too slowly: HeaderTimeoutMSec (default 10000) for the request headers - on HTTP/1.1 counted from when the connection opens or the next request can be read, on HTTP/2 also covering the connection preface and each frame - then RequestTimeout...
Full description »
property RequestTimeoutMSec: Integer read fRequestTimeoutMSec write SetRequestTimeoutMSec default cHttpDefaultRequestTimeoutMSec;
classtHTTP11Limits
inherits from tCustomHTTPLimits
The HTTP/1.1 bounds. Read PER REQUEST, so a change applies to the next request even on a connection that is already open.
constructor Create(aOwner: TComponent); override;
procedure AssignTo(Dest: TPersistent); override;
How much of an unterminated header block will be buffered before the peer gets 431 and is disconnected. Bounds a peer that opens a request and never finishes the head.
property MaxRequestsPerConnection: Integer read fMaxRequestsPerConnection write SetMaxRequestsPerConnection default cMaxRequestsPerConn;
The counterpart of tHTTP2Limits.MaxStreamsPerConnection: requests one connection may serve before it is closed.
Full description »
classtHTTP2Limits
inherits from tCustomHTTPLimits
The HTTP/2 bounds. Copied into a connection's engine by ApplyTo when its session is created, so a change applies to connections opened AFTERWARDS - and two of them (MaxConcurrentStreams, HeaderListBytes) are announced to that peer in its opening SETTINGS, where enforcing a changed value mid-connection without re-announcing it would be worse than not changing it at all.
constructor Create(aOwner: TComponent); override;
procedure AssignTo(Dest: TPersistent); override;
procedure ApplyTo(aConn: tHttp2Conn);
Stamps this configuration onto a freshly created engine, before Opened.
property ConnBodyBytes: Integer read fConnBodyBytes write SetConnBodyBytes default cMaxConnBodyBytes;
Assembled bodies summed across every live stream on ONE connection. Without it the real bound was BodyBytes x MaxConcurrentStreams - 8 MiB x 100 = 800 MiB on a single connection - because the two caps were never multiplied out.
Full description »
property ConnResponseBytes: Integer read fConnResponseBytes write SetConnResponseBytes default cMaxConnResponseBytes;
THE RESPONSE SIDE OF THE SAME ARITHMETIC. A response set from memory (SetContent, SetContentText, a stream handed over with aOwns=False) is held whole until its last frame is out, and a stalled stream holds it for as long as the peer keeps its window shut - so without a bound the memory a connect...
Full description »
property TotalResponseBytes: Int64 read fTotalResponseBytes write SetTotalResponseBytes;
The same ceiling SERVER-wide, across every connection this component serves: the outbound twin of TotalBodyBytes, and over it new streams are refused the same way. No default specifier, for the reason TotalBodyBytes gives.
property MaxConcurrentStreams: Integer read fMaxConcurrentStreams write SetMaxConcurrentStreams default cMaxConcurrentStreams;
Peer-opened streams that may be open at once; further ones are refused with REFUSED_STREAM. Announced in the opening SETTINGS.
Largest assembled COMPRESSED header block, across a HEADERS and all its CONTINUATIONs. Half of the CONTINUATION-flood guard.
property MaxContinuationFrames: Integer read fMaxContinuationFrames write SetMaxContinuationFrames default cMaxContinuationFrames;
The other half: how many frames one header block may span.
NOT the same bound as HeaderBlockBytes: this one is the DECODED list (RFC 9113 name+value+32 per field), which is what HPACK can expand a small block into. A 256 KiB block of one-octet indexed references decodes to roughly a gigabyte, so the compressed cap cannot stand in for it. Advertised as SETTINGS_MAX_HEADER_LIST_SIZE and enforced locally, because on the wire that parameter is only advice.
property MaxStreamsPerConnection: Integer read fMaxStreamsPerConnection write SetMaxStreamsPerConnection default cMaxStreamsPerConnection;
The first RATE control here - everything above bounds how BIG one thing may be, these two bound how MANY.
Full description »
property MaxUnproductiveFrames: Integer read fMaxUnproductiveFrames write SetMaxUnproductiveFrames default cMaxUnproductiveFrames;
Budget for frames that make the server work without advancing any request: PING and SETTINGS (each obliges an answer), PRIORITY (ignored outright), RST_STREAM, zero-length DATA on an open stream, unknown frame types and refused HEADERS - the CVE-2019-951x family, where a peer sends 9-octet frames...
Full description »
classTsmCustomHTTPSProtocol
(no public members)
classtHttpAltSvcOptions
inherits from TPersistent
Lets an HTTP/1.1 or HTTP/2 component tell clients, in an Alt-Svc response field, that the same site is served over HTTP/3. Off by default. Set Source to the TsmHTTPSv3, Origin to the site, then Enabled := True, all while the TCP server is inactive (otherwise ETLSAsyncServer). Responses to requests for Origin then carry h3=":<port>"; ma=<MaxAge> while the QUIC listener is active, and clear while it is not. Enabling it asserts that this origin is reachable on that UDP port with the same certificate and content; nothing here can check that. See HTTP.txt section 16.3.
constructor Create(aOwner: TsmCustomHTTPSProtocol);
destructor Destroy; override;
procedure Assign(aSource: TPersistent); override;
property Enabled: Boolean read GetEnabled write SetEnabled default False;
property Source: TComponent read GetSource write SetSource;
The TsmHTTPSv3 to advertise (a component that does not implement iHttpAltSvcSource raises). If it is freed, matching responses carry clear from then on.
property Origin: string read GetOrigin write SetOrigin;
The site, as one HTTPS origin without a path, for example 'https://www.example.com'; only requests for this origin get the field (DNS case and an explicit :443 do not matter). The host is an ASCII DNS name (A-labels for IDNs), dotted IPv4 or bracketed IPv6; anything else raises. Empty, the default, adds no field.
property PublicPort: Word read GetPublicPort write SetPublicPort default 0;
The UDP port to advertise. 0, the default, advertises the port the QUIC listener bound; set it when NAT maps a different public port.
property MaxAge: Integer read GetMaxAge write SetMaxAge default 60;
Seconds, 0..86400, a client may remember the advertisement. A client that misses a later clear keeps using it for that long.
classTsmCustomHTTPSProtocol
inherits from TComponent
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function TryChargeBody(aBytes: Integer): Boolean;
Charged by every wire session before it buffers request-body octets and released when it lets go. Safe from any thread.
Full description »
procedure ReleaseBody(aBytes: Integer);
property BodyBytesHeld: Int64 read GetBodyBytesHeld;
Request-body octets currently buffered across every connection this protocol serves, and the most ever held. These are the MEASUREMENTS; the ceiling is Limits.TotalBodyBytes. Size that from these rather than from guesswork.
» member page
property BodyBytesHighWater: Int64 read fBodyBytesHighWater;
procedure AddHandler(const aPath: string; const aHandler: iHttpRequestHandler);
procedure AddEvent(const aPath: string; aEvent: tHttpRequestEvent);
procedure AddFile(const aReqPath, aPhysicalFile: string);
procedure AddFiles(const aMap: array of THttpFileMap);
function AppProtocol: iAppProtocol;
Register this with TsmAsyncTLSServer.Protocols.AddProtocol.
» member page
property Router: iHttpRouter read GetRouter write SetRouter;
Assign ONE router to both protocol components to register handlers once.
» member page
property SessionProvider: iHttpSessionProvider read fSessionProvider write fSessionProvider;
Replaces the per-connection session a request would otherwise get. Leave it nil - the default - and every request on a connection shares one session that lives and dies with that connection; see iHttpSession, and read what it says about the difference between that and a browser session before dec...
Full description »
property AltSvc: tHttpAltSvcOptions read fAltSvc write SetAltSvc;
Automatic Alt-Svc advertisement of an HTTP/3 endpoint; see tHttpAltSvcOptions. Off by default. The field is added after the handler has run, also to 404 and 425 answers; a response whose handler set Alt-Svc itself is left as it is. Plaintext redirects and requests refused before dispatch get none.
» member page
property EarlyDataPolicy: tEarlyDataPolicy read fEarlyDataPolicy write fEarlyDataPolicy default edpRefuse;
What to do with a request that arrived as TLS 1.3 0-RTT - see tEarlyDataPolicy. Defaults to edpRefuse, which answers 425 (Too Early) and makes the client retry once its handshake has completed. THIS ONLY EVER APPLIES IF THE OPERATOR ENABLED 0-RTT AT THE TLS LAYER. With the shipped default (TLSOptions.EarlyData = edmDisabled) no request is ever early and this property does nothing.
» member page
property AlpnPriority: Integer read fAlpnPriority write SetAlpnPriority default cAlpnPriorityDefault;
Where this protocol sits in the server's ALPN preference list. HIGHER IS PREFERRED, and the SERVER's order is what decides - the client's ordering is ignored beyond membership (RFC 7301 sec.3.2, and see TCustomTLS_ContentLayer.PickProtocol, which walks our list outermost).
Full description »
property Server: TsmAsyncTLSServer read fServer write SetServer;
The async TLS server this protocol is served by. Assigning it registers this protocol with that server's registry (and clearing it unregisters), so an application declares the association in the Object Inspector instead of calling Protocols.AddProtocol from code.
Full description »
property OnRequest: tHttpRequestEvent read fOnRequest write fOnRequest;
Limits is NOT published here: the base has no way to say which wire's bounds it holds, and a component that offered bounds inert on its own protocol would be publishing configuration that does nothing.
Full description »
property IsFallback: Boolean read fIsFallback write fIsFallback default False;
THE protocol that answers a connection which negotiated nothing - a client that offered no ALPN, and every connection accepted on the server's PlainTextRedirectPort, which has no TLS to negotiate in.
Full description »
property PlainTextResources: tPlainTextRules read fPlainTextResources write fPlainTextResources;
Where a plaintext request accepted on the server's PlainTextRedirectPort is turned into a redirect. Handling it is the whole reason that port exists.
Full description »
property OnPlainTextRedirect: tPlainTextRedirectEvent read fOnPlainTextRedirect write fOnPlainTextRedirect;
property OnBodyRefused: tHttpBodyRefusedEvent read fOnBodyRefused write fOnBodyRefused;
A REQUEST BODY WAS REFUSED by one of the Limits, on either wire - once per refusal, with the peer's answer already on its way: - a Content-Length over BodyBytes, or on HTTP/2 over ConnBodyBytes: 413 before any of the body is taken in - on HTTP/1.1 followed by the close, on HTTP/2 by RST_STREAM(NO...
Full description »
inherits from TsmCustomHTTPSProtocol
property Limits: tHTTP11Limits read GetLimits write SetLimits;
The HTTP/1.1 bounds - see tHTTP11Limits and its base, where each one is documented with the hole it exists to close. Defaults reproduce the previous hard-coded behaviour exactly.
» member page
inherits from TsmCustomHTTPSProtocol
procedure ChargeResponse(aBytes: Int64);
Memory-held response octets taken on and let go by every connection's engine, and the question each asks before opening a stream. Safe from any thread. Charging is never refused - by then the response exists - so the bound is applied where it costs nothing: at stream open.
» member page
procedure ReleaseResponse(aBytes: Int64);
function ResponseBudgetFull: Boolean;
property ResponseBytesHeld: Int64 read GetResponseBytesHeld;
Response octets currently held in memory across every connection, and the most ever held. The ceiling is Limits.TotalResponseBytes.
» member page
property ResponseBytesHighWater: Int64 read fResponseBytesHighWater;
property Limits: tHTTP2Limits read GetLimits write SetLimits;
The HTTP/2 bounds - see tHTTP2Limits and its base, where each one is documented with the hole it exists to close. Defaults reproduce the previous hard-coded behaviour exactly.
» member page
Types (enumerations, sets, aliases)
typetEarlyDataPolicy
tEarlyDataPolicy and its values are declared in StreamSec.Http.Server and shared by all three HTTP components; these aliases let code that uses only this unit name them.
tEarlyDataPolicy = StreamSec.Http.Server.tEarlyDataPolicy;
proctPlainTextRedirectEvent
Answers one plaintext request accepted on the server's PlainTextRedirectPort. aHost and aTarget are the peer's, and untrusted; aLocation and aStatusCode arrive holding the default answer, so a handler that changes nothing still redirects. aLocation := '' refuses without a response. See TsmCustomHTTPSProtocol.OnPlainTextRedirect.
tPlainTextRedirectEvent = procedure (Sender: TObject;
const aHost, aTarget: string;
var aLocation: string;
var aStatusCode: Integer) of object;
Routines