Class ProxyResults
Factory methods that build synthetic Response or StreamingProxyResult objects for use with Respond(Response, bool) and RespondStreaming(StreamingProxyResult, bool).
Inherited Members
Namespace: Titanium.Web.Proxy.Http
Assembly: Titanium.Web.Proxy.dll
Syntax
public static class ProxyResults
Methods
| Edit this page View SourceBytes(byte[], string, HttpStatusCode)
Builds a buffered response from raw bytes.
Declaration
public static Response Bytes(byte[] data, string contentType, HttpStatusCode status = HttpStatusCode.OK)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | Body bytes. |
| string | contentType | Full Content-Type value (for example |
| HttpStatusCode | status | HTTP status code. |
Returns
| Type | Description |
|---|---|
| Response | A response ready to pass to Respond(Response, bool). |
File(string, string, HttpStatusCode)
Builds a streamed response that serves a file from disk without buffering it in memory.
Declaration
public static StreamingProxyResult File(string path, string contentType, HttpStatusCode status = HttpStatusCode.OK)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Path to the file. |
| string | contentType | Full Content-Type value. |
| HttpStatusCode | status | HTTP status code. |
Returns
| Type | Description |
|---|---|
| StreamingProxyResult | A streaming result for RespondStreaming(StreamingProxyResult, bool). |
Remarks
Does not handle HTTP Range requests. Clients expecting 206 Partial Content (browser
<video>, download managers with resume) must use Stream(HttpStatusCode, string, Func<Stream, CancellationToken, Task>, long?) with custom
range logic instead.
Exceptions
| Type | Condition |
|---|---|
| FileNotFoundException | The file does not exist. |
Html(string, HttpStatusCode)
Builds a buffered HTML response.
Declaration
public static Response Html(string content, HttpStatusCode status = HttpStatusCode.OK)
Parameters
| Type | Name | Description |
|---|---|---|
| string | content | HTML body. |
| HttpStatusCode | status | HTTP status code. |
Returns
| Type | Description |
|---|---|
| Response | A response ready to pass to Respond(Response, bool). |
Remarks
Sets Content-Type: text/html; charset=utf-8. For API clients that expect JSON, use
Json<T>(T, HttpStatusCode, JsonTypeInfo<T>?) instead.
Json<T>(T, HttpStatusCode, JsonTypeInfo<T>?)
Builds a buffered JSON response.
Declaration
public static Response Json<T>(T value, HttpStatusCode status = HttpStatusCode.OK, JsonTypeInfo<T>? typeInfo = null)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | Value to serialize. |
| HttpStatusCode | status | HTTP status code. |
| JsonTypeInfo<T> | typeInfo | Optional source-generated type info for NativeAOT scenarios. |
Returns
| Type | Description |
|---|---|
| Response | A response ready to pass to Respond(Response, bool). |
Type Parameters
| Name | Description |
|---|---|
| T | Type to serialize. |
Remarks
Uses JsonSerializer. Pass a JsonTypeInfo<T> for NativeAOT / source-gen scenarios. For Newtonsoft.Json callers, serialize manually and use Text(string, HttpStatusCode).
NoContent()
Builds a 204 No Content response.
Declaration
public static Response NoContent()
Returns
| Type | Description |
|---|---|
| Response | A response ready to pass to Respond(Response, bool). |
Redirect(string, HttpStatusCode)
Builds a redirect response with a Location header.
Declaration
public static Response Redirect(string url, HttpStatusCode status = HttpStatusCode.Found)
Parameters
| Type | Name | Description |
|---|---|---|
| string | url | Redirect target URL. |
| HttpStatusCode | status | Redirect status (default 302 Found). |
Returns
| Type | Description |
|---|---|
| Response | A response ready to pass to Respond(Response, bool). |
Remarks
Default status is 302 Found. Use MovedPermanently (301) for canonical URL changes, or TemporaryRedirect (307) / PermanentRedirect (308) to preserve the request method.
Stream(HttpStatusCode, string, Func<Stream, CancellationToken, Task>, long?)
Builds a streamed synthetic response with a caller-supplied body writer.
Declaration
public static StreamingProxyResult Stream(HttpStatusCode status, string contentType, Func<Stream, CancellationToken, Task> writeBody, long? contentLength = null)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpStatusCode | status | HTTP status code. |
| string | contentType | Full Content-Type value. |
| Func<Stream, CancellationToken, Task> | writeBody | Delegate that writes the body to the provided stream. |
| long? | contentLength | When set, the body is written with fixed length framing; otherwise chunked / DATA framing is used. |
Returns
| Type | Description |
|---|---|
| StreamingProxyResult | A streaming result for RespondStreaming(StreamingProxyResult, bool). |
Text(string, HttpStatusCode)
Builds a buffered plain-text response.
Declaration
public static Response Text(string content, HttpStatusCode status = HttpStatusCode.OK)
Parameters
| Type | Name | Description |
|---|---|---|
| string | content | Text body. |
| HttpStatusCode | status | HTTP status code. |
Returns
| Type | Description |
|---|---|
| Response | A response ready to pass to Respond(Response, bool). |
Remarks
Sets Content-Type: text/plain; charset=utf-8. For Newtonsoft.Json callers, serialize
manually and pass the JSON string here.
WithStatus(HttpStatusCode, string)
Builds a buffered response with any status and a plain-text body.
Declaration
public static Response WithStatus(HttpStatusCode status, string body = "")
Parameters
| Type | Name | Description |
|---|---|---|
| HttpStatusCode | status | HTTP status code. |
| string | body | Plain-text body. |
Returns
| Type | Description |
|---|---|
| Response | A response ready to pass to Respond(Response, bool). |