Skip to main content

StreamingRequest class

An HTTP request whose body is read as a stream while it is still arriving. Declare it as the parameter of an HttpHandlerAttribute method, in place of Request, to accept uploads too large to hold in memory.

public sealed class StreamingRequest : RequestHead

Public Members​

namedescription
Body { get; }The request body as a read-only, forward-only stream.
CanHaveBody { get; }Whether the request can carry a body. It is false for a request sent without one, as a GET usually is.

Remarks​

The handler can start before the body has arrived. The method, path, query, headers and cancellation token are inherited from RequestHead.

Examples​

[HttpHandler]
public static async Task<Response> HandleAsync(StreamingRequest request)
{
long length = 0;
var buffer = new byte[64 * 1024];
int read;
while ((read = await request.Body.ReadAsync(buffer, request.Aborted)) != 0)
length += read;
return Response.Text($"Received {length} bytes");
}

See Also​