ServerResponse
Namespace: Vercel.AI.Util
public sealed class ServerResponseByte sink with status, headers, and optional write backpressure.
Mirrors the subset of Node ServerResponse used by the text-stream helpers.
Inheritance: object
Constructors
Section titled “Constructors”ServerResponse()
Section titled “ServerResponse()”public ServerResponse()Creates an empty response.
Properties
Section titled “Properties”DrainCount
Section titled “DrainCount”public int DrainCount { get; }How many times SimulateDrain() ran.
Value: int
EnableBackpressure
Section titled “EnableBackpressure”public bool EnableBackpressure { get; set; }When true, the first write succeeds and later writes return false until SimulateDrain().
Value: bool
public bool Ended { get; }Whether End() has run.
Value: bool
public Action<ServerResponse>? Flush { get; set; }Called after each successful Byte%5b%5d) with this response.
Value: Action<ServerResponse>
Headers
Section titled “Headers”public Dictionary<string, object> Headers { get; }Lowercased headers. Repeated names become a string array.
Value: Dictionary<string, object>
StatusCode
Section titled “StatusCode”public int StatusCode { get; }Status code passed to String).
Value: int
StatusMessage
Section titled “StatusMessage”public string StatusMessage { get; }Status text passed to String).
Value: string
WriteCallCount
Section titled “WriteCallCount”public int WriteCallCount { get; }How many times Byte%5b%5d) was called.
Value: int
WrittenChunks
Section titled “WrittenChunks”public List<byte[]> WrittenChunks { get; }Chunks accepted by Byte%5b%5d).
Value: List<byte[]>
Methods
Section titled “Methods”public void End()Marks the response finished.
GetDecodedChunks()
Section titled “GetDecodedChunks()”public List<string> GetDecodedChunks()Decodes each written chunk as UTF-8.
Returns: List<string>
SetHeaders(HeaderCollection?)
Section titled “SetHeaders(HeaderCollection?)”public void SetHeaders(HeaderCollection? headers)Stores headers, lowercasing names and grouping duplicates.
Parameters
| Name | Type | Description |
|---|---|---|
headers |
HeaderCollection |
SimulateDrain()
Section titled “SimulateDrain()”public void SimulateDrain()Releases a write that returned false.
WaitForDrainAsync()
Section titled “WaitForDrainAsync()”public Task WaitForDrainAsync()Completes when SimulateDrain() runs, or at once when it already ran after the last held write.
Returns: Task
WaitForEndAsync()
Section titled “WaitForEndAsync()”public Task WaitForEndAsync()Completes when End() runs.
Returns: Task
Write(byte[])
Section titled “Write(byte[])”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
WriteHead(int, string?)
Section titled “WriteHead(int, string?)”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 |
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product