internal static EndpointComputerToValueTask GetRunProxyComputer(EndpointComputerToValueTask endpointComputer) { return(async(context, args) => { var endpoint = await GetEndpointFromComputerAsync(context, endpointComputer).ConfigureAwait(false); return $"{endpoint}{context.Request.Path}{context.Request.QueryString}"; }); }
internal static EndpointComputerToValueTask GetRunProxyComputer(EndpointComputerToValueTask endpointComputer) { return(async(context, args) => { var endpoint = await GetEndpointFromComputerAsync(context, endpointComputer).ConfigureAwait(false); // Remove trailing slashes when `RunProxy` endpoints are computed, since paths are appended ot them. endpoint = endpoint.TrimTrailingSlashes(); return $"{endpoint}{context.Request.Path}{context.Request.QueryString}"; }); }
/// <summary> /// Terminating middleware which creates a proxy over a specified endpoint. /// </summary> /// <param name="app">The ASP.NET <see cref="IApplicationBuilder"/>.</param> /// <param name="httpEndpointComputer">The HTTP endpoint to use. This takes the form `(<see cref="HttpContext"/>, <see cref="IDictionary{String, Object}"/>) => <see cref="ValueTask{String}"/>`.</param> /// <param name="wsEndpointComputer">The WS endpoint to use. This takes the form `(<see cref="HttpContext"/>, <see cref="IDictionary{String, Object}"/>) => <see cref="ValueTask{String}"/>`.</param> /// <param name="httpBuilderOptionsAction">The HTTP options builder action to use. This takes the form `(<see cref="IHttpProxyOptionsBuilder"/>) => void`.</param> /// <param name="wsBuilderOptionsAction">The WS options builder action to use. This takes the form `(<see cref="IWsProxyOptionsBuilder"/>) => void`.</param> public static void RunProxy( this IApplicationBuilder app, EndpointComputerToValueTask httpEndpointComputer, EndpointComputerToValueTask wsEndpointComputer, Action <IHttpProxyOptionsBuilder> httpBuilderOptionsAction = null, Action <IWsProxyOptionsBuilder> wsBuilderOptionsAction = null) { app.RunProxy(builder => builder .UseHttp(httpBuilder => httpBuilder .WithEndpoint(httpEndpointComputer) .WithOptions(httpBuilderOptionsAction) ) .UseWs(wsBuilder => wsBuilder .WithEndpoint(wsEndpointComputer) .WithOptions(wsBuilderOptionsAction) ) ); }
/// <inheritdoc/> public IHttpProxyBuilder WithEndpoint(EndpointComputerToValueTask endpointComputer) { _endpointComputer = endpointComputer; return(this); }
internal HttpProxy(EndpointComputerToValueTask endpointComputer, HttpProxyOptions options) { EndpointComputer = endpointComputer; Options = options; }
internal static ValueTask <string> GetEndpointFromComputerAsync(this HttpContext context, EndpointComputerToValueTask computer) => computer(context, context.GetRouteData().Values);
/// <summary> /// Terminating middleware which creates a proxy over a specified endpoint. /// </summary> /// <param name="app">The ASP.NET <see cref="IApplicationBuilder"/>.</param> /// <param name="wsEndpointComputer">The WS endpoint to use. This takes the form `(<see cref="HttpContext"/>, <see cref="IDictionary{String, Object}"/>) => <see cref="ValueTask{String}"/>`.</param> /// <param name="wsBuilderOptionsAction">The WS options builder action to use. This takes the form `(<see cref="IWsProxyOptionsBuilder"/>) => void`.</param> public static void RunWsProxy(this IApplicationBuilder app, EndpointComputerToValueTask wsEndpointComputer, Action <IWsProxyOptionsBuilder> wsBuilderOptionsAction = null) => app.RunWsProxy(builder => builder .WithEndpoint(wsEndpointComputer) .WithOptions(wsBuilderOptionsAction) );
/// <summary> /// Terminating middleware which creates a proxy over a specified endpoint. /// </summary> /// <param name="app">The ASP.NET <see cref="IApplicationBuilder"/>.</param> /// <param name="httpEndpointComputer">The HTTP endpoint to use. This takes the form `(<see cref="HttpContext"/>, <see cref="IDictionary{String, Object}"/>) => <see cref="ValueTask{String}"/>`.</param> /// <param name="httpBuilderOptionsAction">The HTTP options builder action to use. This takes the form `(<see cref="IHttpProxyOptionsBuilder"/>) => void`.</param> public static void RunHttpProxy(this IApplicationBuilder app, EndpointComputerToValueTask httpEndpointComputer, Action <IHttpProxyOptionsBuilder> httpBuilderOptionsAction = null) => app.RunHttpProxy(builder => builder .WithEndpoint(httpEndpointComputer) .WithOptions(httpBuilderOptionsAction) );
/// <inheritdoc/> public IProxyBuilder UseWs(EndpointComputerToValueTask endpointComputer, Action <IWsProxyOptionsBuilder> builderAction = null) => this.UseWs(wsProxy => wsProxy.WithEndpoint(endpointComputer).WithOptions(builderAction));
/// <inheritdoc/> public IProxyBuilder UseHttp(EndpointComputerToValueTask endpointComputer, Action <IHttpProxyOptionsBuilder> builderAction = null) => this.UseHttp(httpProxy => httpProxy.WithEndpoint(endpointComputer).WithOptions(builderAction));