Skip to content

ServerResponse

Namespace: Vercel.AI.Util

public sealed class ServerResponse

Byte sink with status, headers, and optional write backpressure. Mirrors the subset of Node ServerResponse used by the text-stream helpers.

Inheritance: object

View source

public ServerResponse()

Creates an empty response.

View source

public int DrainCount { get; }

How many times SimulateDrain() ran.

Value: int

View source

public bool EnableBackpressure { get; set; }

When true, the first write succeeds and later writes return false until SimulateDrain().

Value: bool

View source

public bool Ended { get; }

Whether End() has run.

Value: bool

View source

public Action<ServerResponse>? Flush { get; set; }

Called after each successful Byte%5b%5d) with this response.

Value: Action<ServerResponse>

View source

public Dictionary<string, object> Headers { get; }

Lowercased headers. Repeated names become a string array.

Value: Dictionary<string, object>

View source

public int StatusCode { get; }

Status code passed to String).

Value: int

View source

public string StatusMessage { get; }

Status text passed to String).

Value: string

View source

public int WriteCallCount { get; }

How many times Byte%5b%5d) was called.

Value: int

View source

public List<byte[]> WrittenChunks { get; }

Chunks accepted by Byte%5b%5d).

Value: List<byte[]>

View source

public void End()

Marks the response finished.

View source

public List<string> GetDecodedChunks()

Decodes each written chunk as UTF-8.

Returns: List<string>

View source

public void SetHeaders(HeaderCollection? headers)

Stores headers, lowercasing names and grouping duplicates.

Parameters

Name Type Description
headers HeaderCollection

View source

public void SimulateDrain()

Releases a write that returned false.

View source

public Task WaitForDrainAsync()

Completes when SimulateDrain() runs, or at once when it already ran after the last held write.

Returns: Task

View source

public Task WaitForEndAsync()

Completes when End() runs.

Returns: Task

View source

public bool Write(byte[] chunk)

Appends <code class=“paramref”>chunk</code>. Returns false when the caller should wait for drain.

Parameters

Name Type Description
chunk byte[]

Returns: bool

View source

public void WriteHead(int statusCode, string? statusText = null)

Sets the status code and, when provided, the status text.

Parameters

Name Type Description
statusCode int
statusText string

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product