Beispiel #1
0
        public ReverseProxyMiddleware(RequestDelegate next, ReverseProxyOptions options, ILoggerFactory loggerFactory)
        {
            _next    = next;
            _options = options;

            _log        = loggerFactory.CreateLogger <ReverseProxyMiddleware>();
            _httpClient = new HttpClient();
        }
Beispiel #2
0
        /// <summary>
        /// Adds the reverse proxy middleware to the request pipeline. This should be the last middleware in the pipeline.
        /// </summary>
        /// <param name="app">The application builder instance.</param>
        /// <param name="proxyToScheme">The scheme of the host to proxy to.</param>
        /// <param name="proxyToHost">The host to proxy to.</param>
        /// <param name="proxyToPort">The port of the host to proxy to. Defaults to 80.</param>
        public static void UseReverseProxy(this IApplicationBuilder app, string proxyToScheme, string proxyToHost, Int32 proxyToPort = 80)
        {
            var loggerFactory = (ILoggerFactory)app.ApplicationServices.GetService(typeof(ILoggerFactory));

            var options = new ReverseProxyOptions {
                Scheme = proxyToScheme, Host = proxyToHost, Port = proxyToPort
            };

            app.UseMiddleware <ReverseProxyMiddleware>(options, loggerFactory);
        }