Skip to main content

RawContent

property RawContent: TBytes read;

Example

procedure ScriptEvent(var Value: variant);
begin
{ The endpoint must already have enforced a trusted maximum body size. }
if (Request <> nil) and (Request.ContentLength <= 1048576) then
Value := Length(Request.RawContent)
else
Value := 0;
end;

Usage

RawContent allocates and returns a complete byte-array copy of the current request stream while restoring its original position.

Additional Technical Info

RawContent reads Velox's current Content stream into a new dynamic byte array. The Indy bridge saves Position, seeks to zero, allocates Size bytes, performs one Read(Buffer, 0, Length) call and restores the saved position in finally.

The returned array is a detached byte copy; changing it does not alter the stream. The operation itself allocates memory proportional to the entire current stream size and blocks while copying. It does not enforce a limit, decompress ContentEncoding, validate ContentType, verify a signature/hash or parse a format.

The implementation ignores the count returned by its single Read. A stream that short-reads without raising can leave the unread tail at its initial zero values while still returning an array of full Size. Ordinary memory/string streams usually fill the request, but callers must not generalise this as a checked ReadExactly contract.

Position restoration occurs even when the read raises, but concurrent/shared stream mutation can invalidate size/position assumptions. Very large Size/allocation, seek/read errors and an invalid directly constructed request can raise. Enforce body limits before this property and process arbitrary binary data with a parser that has its own size/depth limits.

Test Request for nil. Do not assume the bytes are UTF-8; ContentString has separate decoding quirks.

External references

Created 2026-07-15