HTTP API Toolkit HTTP API Toolkit
HTTP API Toolkit HTTP API Toolkit
DocFX + Singulink = ♥

Search Results for

    Method UseCloudflareForwarding

    UseCloudflareForwarding(IApplicationBuilder)

    Adds middleware that trusts the client address and scheme forwarded by Cloudflare. Requires the services registered by AddCloudflareForwarding(IServiceCollection, Action<CloudflareForwardingOptions>?).

    Declaration
    public static IApplicationBuilder UseCloudflareForwarding(this IApplicationBuilder app)
    Parameters
    Type Name Description
    IApplicationBuilder app

    The application.

    Returns
    Type Description
    IApplicationBuilder
    Remarks

    Call this first in the pipeline, before any middleware that uses the client's address or the request scheme (such as HTTPS redirection, rate limiting or request logging).

    For requests whose connection comes from one of Cloudflare's IP ranges (or from one of the TrustedProxyNetworks), RemoteIpAddress is set to the address in the CF-Connecting-IP header and Scheme to the value of the X-Forwarded-Proto header (http or https). Missing or invalid values leave the request unchanged.

    All other requests are direct connections: their address and scheme are left unchanged and every request header whose name starts with CF- is removed, so Cloudflare headers such as CF-IPCountry can be trusted whenever they are present. A direct connection with a CF-Connecting-IP header that has another address is logged as a warning, once an hour for each connection address.

    Until Cloudflare's IP ranges are available, requests through Cloudflare cannot be told apart from direct connections, so every request is refused with a 503 Service Unavailable response in the toolkit's error format, with the error code CloudflareRangesUnavailable and a Retry-After header. This only happens when the ranges could not be downloaded at startup and there is no usable saved copy (see SavedRangesPath). The response is written before the middleware that comes after this one runs, such as CORS, so it has no CORS headers and pages on other origins cannot read it.

    Exceptions
    Type Condition
    InvalidOperationException

    The Cloudflare forwarding services are not registered.

    © Singulink. All rights reserved.