Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        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));
            }

            _next    = next ?? throw new ArgumentNullException(nameof(next));
            _options = options.Value;
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Runs proxy forwarding requests to the server specified by base uri.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="baseUri">Destination base uri</param>
        public static void RunProxy(this IApplicationBuilder app, Uri baseUri)
        {
            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)
            };

            app.UseMiddleware <ProxyMiddleware>(Options.Create(options));
        }