Beispiel #1
0
        public HttpProxyOptions Process()
        {
            string key = string.Empty;
            string ip  = string.Empty;

            HttpProxyOptions options = HttpProxyOptionsBuilder.Instance
                                       .WithShouldAddForwardedHeaders(true)
                                       .WithBeforeSend((c, hrm) =>
            {
                return(Task.CompletedTask);
            })
                                       .WithAfterReceive(async(c, hrm) =>
            {
                if (hrm.IsSuccessStatusCode)
                {
                    if (hrm.Headers.TryGetValues("TN-PID", out IEnumerable <string> strs))
                    {
                        if (int.TryParse(strs.FirstOrDefault(), out int pid))
                        {
                            hrm.Headers.Add("TN-IST", await _drivers.CreateInstance(pid, c.Request.Headers["TN-KEY"]));
                        }
                    }
                }

                // Delete headers comming from tenet
                c.Response.Headers.Remove("TN-KID");
                c.Response.Headers.Remove("TN-PID");
            }).Build();

            return(options);
        }
Beispiel #2
0
        public IdentityController(NodeService node)
        {
            this.node = node;

            options = HttpProxyOptionsBuilder.Instance.WithBeforeSend((c, hrm) =>
            {
                hrm.Headers.Add("Node-Api-Key", node.NodeApiKey);
                return(Task.CompletedTask);
            }).Build();
        }
 public void SetProxy(HttpProxyOptions options)
 {
     //this.logger.Log("Setting proxy to " + options.host_address);
     //System.setProperty("http.proxyHost", options.host_address);
     //System.setProperty("http.proxyPort", string.valueOf(options.port));
     //System.setProperty("http.proxyUser", options.username);
     //System.setProperty("http.proxyPassword", options.password);
     //Authenticator.setDefault(new Authenticator() {
     //
     //public PasswordAuthentication getPasswordAuthentication()
     //{
     //    return new PasswordAuthentication(options.username, options.password.toCharArray());
     //}
 }
Beispiel #4
0
        /// <summary>
        /// 配置 Http 代理
        /// </summary>
        /// <param name="services"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static IServiceCollection ConfigHttpProxy(this IServiceCollection services, Action <HttpProxyBuilder> action)
        {
            services.AddSingleton <IHttpProxyFactory, DefaultHttpProxyFactory>();
            services.AddSingleton <IContentSerializer, XWwwFormUrlencoded>();
            services.AddSingleton <IContentSerializer, Json>();
            services.AddSingleton <IUrlBuilder, DefaultUrlBuilder>();

            HttpProxyBuilder builder = new HttpProxyBuilder(services);

            action(builder);
            builder.AddInterceptor <MockInterceptor>();
            builder.AddInterceptor <ResponseMediaTypeInterceptor>();

            HttpProxyOptions options = new HttpProxyOptions(builder.ClientNameToHostMap);

            services.AddSingleton(options);

            return(services);
        }
Beispiel #5
0
 internal HttpProxy(EndpointComputerToValueTask endpointComputer, HttpProxyOptions options)
 {
     EndpointComputer = endpointComputer;
     Options          = options;
 }
Beispiel #6
0
        /// <summary>
        /// Proxies a request inside of a controller's method body from the request on the controller's route.
        /// </summary>
        /// <param name="controller">The ASP.NET <see cref="ControllerBase"/>.</param>
        /// <param name="httpEndpoint">The HTTP endpoint to use.</param>
        /// <param name="httpProxyOptions">The HTTP options.</param>
        /// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
        public static Task HttpProxyAsync(this ControllerBase controller, string httpEndpoint, HttpProxyOptions httpProxyOptions = null)
        {
            var httpProxy = new HttpProxy((c, a) => new ValueTask <string>(httpEndpoint), httpProxyOptions);

            return(controller.HttpContext.ExecuteHttpProxyOperationAsync(httpProxy));
        }
Beispiel #7
0
        /// <summary>
        /// Proxies a request inside of a controller's method body from the request on the controller's route.
        /// </summary>
        /// <param name="controller">The ASP.NET <see cref="ControllerBase"/>.</param>
        /// <param name="httpEndpoint">The HTTP endpoint to use.</param>
        /// <param name="wsEndpoint">The WS endpoint to use.</param>
        /// <param name="httpProxyOptions">The HTTP options.</param>
        /// <param name="wsProxyOptions">The WS options.</param>
        /// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
        public static Task ProxyAsync(this ControllerBase controller, string httpEndpoint, string wsEndpoint, HttpProxyOptions httpProxyOptions = null, WsProxyOptions wsProxyOptions = null)
        {
            var httpProxy = new HttpProxy((c, a) => new ValueTask <string>(httpEndpoint), httpProxyOptions);
            var wsProxy   = new WsProxy((c, a) => new ValueTask <string>(wsEndpoint), wsProxyOptions);
            var proxy     = new Builders.Proxy(null, httpProxy, wsProxy);

            return(controller.HttpContext.ExecuteProxyOperationAsync(proxy));
        }