KestrunResponse class

Represents an HTTP response in the Kestrun framework, providing methods to write various content types and manage headers, cookies, and status codes.

public class KestrunResponse
parameter description
request The associated KestrunRequest for this response.
bodyAsyncThreshold The threshold in bytes for using async body write operations. Defaults to 8192.

Public Members

name description
KestrunResponse(…) Represents an HTTP response in the Kestrun framework, providing methods to write various content types and manage headers, cookies, and status codes.
AcceptCharset { get; } Global text encoding for all responses. Defaults to UTF-8.
Body { get; set; } Gets or sets the body of the response, which can be a string, byte array, stream, or file info.
BodyAsyncThreshold { get; set; } If the response body is larger than this threshold (in bytes), async write will be used.
ContentDisposition { get; set; } Content-Disposition header value.
ContentType { get; set; } Gets or sets the MIME content type of the response.
Cookies { get; set; } Gets or sets the list of Set-Cookie header values for the response.
Encoding { get; set; } Text encoding for textual MIME types.
Headers { get; set; } Gets or sets the collection of HTTP headers for the response.
RedirectUrl { get; set; } Gets or sets the URL to redirect the response to, if an HTTP redirect is required.
Request { get; } Gets the associated KestrunRequest for this response.
StatusCode { get; set; } Gets or sets the HTTP status code for the response.
ApplyTo(…) Applies the current KestrunResponse to the specified HttpResponse, setting status, headers, cookies, and writing the body.
GetHeader(…) Retrieves the value of the specified header from the response headers.
WriteBinaryResponse(…) Writes a binary response with the specified data, status code, and content type.
WriteBsonResponse(…) Writes a BSON response with the specified input object, status code, and content type.
WriteBsonResponseAsync(…) Asynchronously writes a BSON response with the specified input object, status code, and content type.
WriteCborResponse(…) Writes a CBOR response (binary, efficient, not human-readable).
WriteCborResponseAsync(…) Writes a CBOR response (binary, efficient, not human-readable).
WriteCsvResponse(…) Writes a CSV response with the specified input object, status code, content type, and optional CsvConfiguration.
WriteCsvResponseAsync(…) Asynchronously writes a CSV response with the specified input object, status code, content type, and optional configuration tweak.
WriteErrorResponse(…) Writes an error response with a custom message. Chooses JSON/YAML/XML/plain-text based on override → Accept → default JSON. (2 methods)
WriteErrorResponseAsync(…) Write an error response with a custom message. Chooses JSON/YAML/XML/plain-text based on override → Accept → default JSON. (2 methods)
WriteFileResponse(…) Writes a file response with the specified file path, content type, and HTTP status code.
WriteHtmlResponse(…) Renders the given HTML string with placeholders and writes it as a response.
WriteHtmlResponseAsync(…) Asynchronously writes an HTML response, rendering the provided template string and replacing placeholders with values from the given dictionary.
WriteHtmlResponseFromFile(…) Reads an .html file, merges in placeholders, and writes it.
WriteHtmlResponseFromFileAsync(…) Asynchronously reads an HTML file, merges in placeholders from the provided dictionary, and writes the result as a response.
WriteJsonResponse(…) Writes a JSON response with the specified input object and HTTP status code. (3 methods)
WriteJsonResponseAsync(…) Asynchronously writes a JSON response with the specified input object and HTTP status code. (3 methods)
WriteRedirectResponse(…) Writes an HTTP redirect response with the specified URL and optional message.
WriteResponse(…) Writes a response with the specified input object and HTTP status code. Chooses the response format based on the Accept header or defaults to text/plain.
WriteResponseAsync(…) Asynchronously writes a response with the specified input object and HTTP status code. Chooses the response format based on the Accept header or defaults to text/plain.
WriteStreamResponse(…) Writes a stream response with the specified stream, status code, and content type.
WriteTextResponse(…) Writes a text response with the specified input object, status code, and content type.
WriteTextResponseAsync(…) Asynchronously writes a text response with the specified input object, status code, and content type.
WriteXmlResponse(…) Writes an XML response with the specified input object, status code, and content type.
WriteXmlResponseAsync(…) Asynchronously writes an XML response with the specified input object, status code, and content type.
WriteYamlResponse(…) Writes a YAML response with the specified input object, status code, and content type.
WriteYamlResponseAsync(…) Asynchronously writes a YAML response with the specified input object, status code, and content type.
static readonly TextBasedMimeTypes A set of MIME types that are considered text-based for response content.
static IsTextBasedContentType(…) Determines whether the specified content type is text-based or supports a charset.

Remarks

Initializes a new instance of the KestrunResponse class with the specified request and optional body async threshold.

See Also