コード例 #1
0
        /// <summary>
        /// プロキシエンジンを指定して初期化
        /// </summary>
        /// <param name="engine">プロキシエンジン</param>
        public HttpProxy(Spi.IReadOnlyHttpProxyEngine engine)
        {
            this.proxyEngine         = engine;
            engine.HttpRequestSent  += (sender, args) => this.HttpRequestSent?.Invoke(sender, ReadOnlyHttpRequestEventArgs.Convert(args));
            engine.HttpResponseSent += (sender, args) => this.HttpResponseSent?.Invoke(sender, ReadOnlySessionEventArgs.Convert(args));
            engine.FatalException   += (sender, args) => this.FatalException?.Invoke(sender, ExceptionEventArgs.Convert(args));

            if (engine is Spi.IHttpProxyEngine writableEngine)
            {
                writableEngine.HttpRequestReceived  += (sender, args) => this.HttpRequestReceived?.Invoke(sender, HttpRequestEventArgs.Convert(args));
                writableEngine.HttpResponseReceived += (sender, args) => this.HttpResponseReceived?.Invoke(sender, SessionEventArgs.Convert(args));
            }
            if (engine is Spi.IReadOnlyWebSocketProxyEngine rowsEngine)
            {
                rowsEngine.ClientWebSocketMessageSent += (sender, args) => this.ClientWebSocketMessageSent?.Invoke(sender, ReadOnlyWebSocketMessageEventArgs.Convert(args));
                rowsEngine.ServerWebSocketMessageSent += (sender, args) => this.ServerWebSocketMessageSent?.Invoke(sender, ReadOnlyWebSocketMessageEventArgs.Convert(args));
            }
            if (engine is Spi.IWebSocketProxyEngine wsEngine)
            {
                wsEngine.ClientWebSocketMessageReceived += (sender, args) => this.ClientWebSocketMessageReceived?.Invoke(sender, WebSocketMessageEventArgs.Convert(args));
                wsEngine.ServerWebSocketMessageReceived += (sender, args) => this.ServerWebSocketMessageReceived?.Invoke(sender, WebSocketMessageEventArgs.Convert(args));
            }
        }
コード例 #2
0
 /// <summary>
 /// プロキシエンジンを指定して読み取り専用 HTTP プロキシを作成
 /// </summary>
 /// <param name="engine">プロキシエンジン</param>
 /// <returns>HTTP プロキシ</returns>
 public static IReadOnlyHttpProxy Create(Spi.IReadOnlyHttpProxyEngine engine)
 => new HttpProxy(engine);