/// <summary> /// Runs proxy forwarding requests to the server specified by options. /// </summary> /// <param name="app"></param> /// <param name="options">Proxy options</param> public static void RunProxy(this IApplicationBuilder app, ProxyOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } app.UseMiddleware <ProxyMiddleware>(Options.Create(options)); }
public ProxyMiddleware(RequestDelegate next, IOptions <ProxyOptions> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.Value.Scheme == null) { throw new ArgumentException("Options parameter must specify scheme.", nameof(options)); } if (!options.Value.Host.HasValue) { throw new ArgumentException("Options parameter must specify host.", nameof(options)); } this.next = next ?? throw new ArgumentNullException(nameof(next)); this.options = options.Value; }
/// <summary> /// Runs proxy forwarding requests to the server specified by base uri. /// </summary> /// <param name="app"></param> /// <param name="baseUri">Destination base uri</param> /// <param name="pathFilter">Filter to only proxy request coming on a certain path <example>/api</example></param> public static void RunProxy(this IApplicationBuilder app, Uri baseUri, PathString pathFilter) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (baseUri == null) { throw new ArgumentNullException(nameof(baseUri)); } var options = new ProxyOptions { Scheme = baseUri.Scheme, Host = new HostString(baseUri.Authority), PathBase = baseUri.AbsolutePath, AppendQuery = new QueryString(baseUri.Query), PathFilter = pathFilter }; app.UseMiddleware <ProxyMiddleware>(Options.Create(options)); }