Class HttpTransformer
Inheritance
Namespace: Yarp.ReverseProxy.Forwarder
Assembly: Yarp.ReverseProxy.dll
Syntax
public class HttpTransformer : object
Constructors
| Improve this Doc View SourceHttpTransformer()
Used to create derived instances.
Declaration
protected HttpTransformer()
Fields
| Improve this Doc View SourceDefault
A default set of transforms that adds X-Forwarded-* headers, removes the original Host value and copies all other request and response fields and headers, except for some protocol specific values.
Declaration
public static readonly HttpTransformer Default
Field Value
Type | Description |
---|---|
HttpTransformer |
Empty
An empty transformer that copies all request and response fields and headers, except for some protocol specific values.
Declaration
public static readonly HttpTransformer Empty
Field Value
Type | Description |
---|---|
HttpTransformer |
Methods
| Improve this Doc View SourceTransformRequestAsync(HttpContext, HttpRequestMessage, String)
A callback that is invoked prior to sending the proxied request. All HttpRequestMessage fields are
initialized except RequestUri, which will be initialized after the callback if no value is provided.
See MakeDestinationAddress(String, PathString, QueryString) for constructing a custom request Uri.
The string parameter represents the destination URI prefix that should be used when constructing the RequestUri.
The headers are copied by the base implementation, excluding some protocol headers like HTTP/2 pseudo headers (":authority").
This method may be overridden to conditionally produce a response, such as for error conditions, and prevent the request from
being proxied. This is indicated by setting the HttpResponse.StatusCode
to a value other than 200, or calling HttpResponse.StartAsync()
,
or writing to the HttpResponse.Body
or BodyWriter
.
Declaration
public virtual ValueTask TransformRequestAsync(HttpContext httpContext, HttpRequestMessage proxyRequest, string destinationPrefix)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | The incoming request. |
HttpRequestMessage | proxyRequest | The outgoing proxy request. |
System.String | destinationPrefix | The uri prefix for the selected destination server which can be used to create the RequestUri. |
Returns
Type | Description |
---|---|
ValueTask |
TransformRequestAsync(HttpContext, HttpRequestMessage, String, CancellationToken)
A callback that is invoked prior to sending the proxied request. All HttpRequestMessage fields are
initialized except RequestUri, which will be initialized after the callback if no value is provided.
See MakeDestinationAddress(String, PathString, QueryString) for constructing a custom request Uri.
The string parameter represents the destination URI prefix that should be used when constructing the RequestUri.
The headers are copied by the base implementation, excluding some protocol headers like HTTP/2 pseudo headers (":authority").
This method may be overridden to conditionally produce a response, such as for error conditions, and prevent the request from
being proxied. This is indicated by setting the HttpResponse.StatusCode
to a value other than 200, or calling HttpResponse.StartAsync()
,
or writing to the HttpResponse.Body
or BodyWriter
.
Declaration
public virtual ValueTask TransformRequestAsync(HttpContext httpContext, HttpRequestMessage proxyRequest, string destinationPrefix, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | The incoming request. |
HttpRequestMessage | proxyRequest | The outgoing proxy request. |
System.String | destinationPrefix | The uri prefix for the selected destination server which can be used to create the RequestUri. |
CancellationToken | cancellationToken | Indicates that the request is being canceled. |
Returns
Type | Description |
---|---|
ValueTask |
TransformResponseAsync(HttpContext, Nullable<HttpResponseMessage>)
A callback that is invoked when the proxied response is received. The status code and reason phrase will be copied
to the HttpContext.Response before the callback is invoked, but may still be modified there. The headers will be
copied to HttpContext.Response.Headers by the base implementation, excludes certain protocol headers like
Transfer-Encoding: chunked
.
Declaration
public virtual ValueTask<bool> TransformResponseAsync(HttpContext httpContext, HttpResponseMessage? proxyResponse)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | The incoming request. |
System.Nullable<HttpResponseMessage> | proxyResponse | The response from the destination. This can be null if the destination did not respond. |
Returns
Type | Description |
---|---|
ValueTask<System.Boolean> | A bool indicating if the response should be proxied to the client or not. A derived implementation that returns false may send an alternate response inline or return control to the caller for it to retry, respond, etc. |
TransformResponseAsync(HttpContext, Nullable<HttpResponseMessage>, CancellationToken)
A callback that is invoked when the proxied response is received. The status code and reason phrase will be copied
to the HttpContext.Response before the callback is invoked, but may still be modified there. The headers will be
copied to HttpContext.Response.Headers by the base implementation, excludes certain protocol headers like
Transfer-Encoding: chunked
.
Declaration
public virtual ValueTask<bool> TransformResponseAsync(HttpContext httpContext, HttpResponseMessage? proxyResponse, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | The incoming request. |
System.Nullable<HttpResponseMessage> | proxyResponse | The response from the destination. This can be null if the destination did not respond. |
CancellationToken | cancellationToken | Indicates that the request is being canceled. |
Returns
Type | Description |
---|---|
ValueTask<System.Boolean> | A bool indicating if the response should be proxied to the client or not. A derived implementation that returns false may send an alternate response inline or return control to the caller for it to retry, respond, etc. |
TransformResponseTrailersAsync(HttpContext, HttpResponseMessage)
A callback that is invoked after the response body to modify trailers, if supported. The trailers will be copied to the HttpContext.Response by the base implementation.
Declaration
public virtual ValueTask TransformResponseTrailersAsync(HttpContext httpContext, HttpResponseMessage proxyResponse)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | The incoming request. |
HttpResponseMessage | proxyResponse | The response from the destination. |
Returns
Type | Description |
---|---|
ValueTask |
TransformResponseTrailersAsync(HttpContext, HttpResponseMessage, CancellationToken)
A callback that is invoked after the response body to modify trailers, if supported. The trailers will be copied to the HttpContext.Response by the base implementation.
Declaration
public virtual ValueTask TransformResponseTrailersAsync(HttpContext httpContext, HttpResponseMessage proxyResponse, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | The incoming request. |
HttpResponseMessage | proxyResponse | The response from the destination. |
CancellationToken | cancellationToken | Indicates that the request is being canceled. |
Returns
Type | Description |
---|---|
ValueTask |