Ejemplo n.º 1
0
 public void PrepareForRequest()
 {
     TraceSources.CoreDebug.TraceInformation("ID{0,-5} PrepareForRequest", _handlerId);
     _lastRequestFinished = null;
     _disconnected        = false;
     _inWebSocket         = false;
     _webSocketFunc       = null;
     _environment.Reset();
     _onHeadersList.Clear();
     ReqHeaders.Clear();
     RespHeaders.Clear();
 }
Ejemplo n.º 2
0
        public void LargeResponseBodyWith1AsyncWriteWorks()
        {
            OwinApp app = async env =>
            {
                var responseStream = env.Get <Stream>("owin.ResponseBody");
                var pos            = 0;
                var buffer         = PrepareLargeResponseBuffer(ref pos, 100000);
                await responseStream.WriteAsync(buffer, 0, buffer.Length);
            };

            CheckLargeBody(app);
        }
Ejemplo n.º 3
0
        public void LargeResponseBodyWithFlushAnd1WriteWorks()
        {
            OwinApp app = env =>
            {
                var responseStream = env.Get <Stream>("owin.ResponseBody");
                responseStream.Flush();
                var pos    = 0;
                var buffer = PrepareLargeResponseBuffer(ref pos, 100000);
                responseStream.Write(buffer, 0, buffer.Length);
                return(Task.Delay(0));
            };

            CheckLargeBody(app);
        }
Ejemplo n.º 4
0
        public void LargeResponseBodyWith100WritesWorks()
        {
            OwinApp app = async env =>
            {
                await Task.Delay(1);

                var responseStream = env.Get <Stream>("owin.ResponseBody");
                var pos            = 0;
                for (var i = 0; i < 100; i++)
                {
                    var buffer = PrepareLargeResponseBuffer(ref pos, 1000);
                    responseStream.Write(buffer, 0, buffer.Length);
                }
            };

            CheckLargeBody(app);
        }
Ejemplo n.º 5
0
 void WebSocketAcceptMethod(IDictionary <string, object> dictionary, Func <IDictionary <string, object>, Task> func)
 {
     TraceSources.CoreDebug.TraceInformation("ID{0,-5} WebSocketAcceptMethod", _handlerId);
     if (dictionary != null)
     {
         object value;
         if (dictionary.TryGetValue("websocket.SubProtocol", out value) && value is string)
         {
             RespHeaders.Remove("Sec-WebSocket-Protocol");
             RespHeaders.Add("Sec-WebSocket-Protocol", new[] { (string)value });
         }
     }
     _webSocketFunc = func;
     _inWebSocket   = true;
     StartWaitingTillEndOfAppFunc();
     _webSocketReceiveState             = WebSocketReceiveState.Header;
     _webSocketNextSendIsStartOfMessage = true;
     _webSocketSendBufferUsedSize       = 0;
     Callback.UpgradeToWebSocket();
 }
Ejemplo n.º 6
0
        void CheckLargeBody(OwinApp app)
        {
            var listener = CreateServer(app);

            using (listener)
            {
                var client   = new HttpClient();
                var response = client.GetAsync(HttpClientAddress).Result;
                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
                var result = response.Content.ReadAsByteArrayAsync().Result;
                Assert.AreEqual(100000, result.Length);
                for (var i = 0; i < result.Length; i++)
                {
                    if (result[i] != (i & 0xff))
                    {
                        Assert.Fail("Response is wrong on {0} byte", i);
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public OwinHandler(OwinApp app, IDictionary <string, object> owinCapabilities, int handlerId)
 {
     _app = app;
     _owinCapabilities      = owinCapabilities;
     _handlerId             = handlerId;
     _environment           = new OwinEnvironment(this);
     ReqHeaders             = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase);
     RespHeaders            = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase);
     OnSendingHeadersAction = OnSendingHeadersMethod;
     _webSocketEnv          = new Dictionary <string, object>
     {
         { "websocket.SendAsync", (WebSocketSendAsync)WebSocketSendAsyncMethod },
         { "websocket.ReceiveAsync", (WebSocketReceiveAsync)WebSocketReceiveAsyncMethod },
         { "websocket.CloseAsync", (WebSocketCloseAsync)WebSocketCloseAsyncMethod },
         { "websocket.Version", "1.0" },
         { "websocket.CallCancelled", null }
     };
     DisconnectAction = () =>
     {
         _disconnected = true;
         StartWaitingTillEndOfAppFunc();
         Callback.CloseConnection();
     };
 }
Ejemplo n.º 8
0
 void CheckLargeBody(OwinApp app)
 {
     var listener = CreateServer(app);
     using (listener)
     {
         var client = new HttpClient();
         var response = client.GetAsync(HttpClientAddress).Result;
         Assert.Equal(HttpStatusCode.OK, response.StatusCode);
         var result = response.Content.ReadAsByteArrayAsync().Result;
         Assert.Equal(100000, result.Length);
         for (var i = 0; i < result.Length; i++)
         {
             if (result[i] != (i & 0xff)) Assert.True(false,string.Format("Response is wrong on {0} byte", i));
         }
     }
 }
Ejemplo n.º 9
0
 void WebSocketAcceptMethod(IDictionary<string, object> dictionary, Func<IDictionary<string, object>, Task> func)
 {
     TraceSources.CoreDebug.TraceInformation("ID{0,-5} WebSocketAcceptMethod", _handlerId);
     if (dictionary != null)
     {
         object value;
         if (dictionary.TryGetValue("websocket.SubProtocol", out value) && value is string)
         {
             RespHeaders.Remove("Sec-WebSocket-Protocol");
             RespHeaders.Add("Sec-WebSocket-Protocol", new[] { (string)value });
         }
     }
     _webSocketFunc = func;
     _inWebSocket = true;
     _webSocketReceiveState = WebSocketReceiveState.Header;
     _webSocketNextSendIsStartOfMessage = true;
     _webSocketSendBufferUsedSize = 0;
     Callback.UpgradeToWebSocket();
 }
Ejemplo n.º 10
0
 public void PrepareForRequest()
 {
     TraceSources.CoreDebug.TraceInformation("ID{0,-5} PrepareForRequest", _handlerId);
     _inWebSocket = false;
     _webSocketFunc = null;
     _environment.Reset();
     _onHeadersList.Clear();
     ReqHeaders.Clear();
     RespHeaders.Clear();
 }
Ejemplo n.º 11
0
 public OwinHandler(OwinApp app, IDictionary<string, object> owinCapabilities, int handlerId)
 {
     _app = app;
     _owinCapabilities = owinCapabilities;
     _handlerId = handlerId;
     _environment = new OwinEnvironment(this);
     ReqHeaders = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
     RespHeaders = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
     OnSendingHeadersAction = OnSendingHeadersMethod;
     _webSocketEnv = new Dictionary<string, object>
         {
             {"websocket.SendAsync", (WebSocketSendAsync) WebSocketSendAsyncMethod},
             {"websocket.ReceiveAsync", (WebSocketReceiveAsync) WebSocketReceiveAsyncMethod},
             {"websocket.CloseAsync", (WebSocketCloseAsync) WebSocketCloseAsyncMethod},
             {"websocket.Version", "1.0"},
             {"websocket.CallCancelled", null}
         };
 }