예제 #1
0
        /// <summary>
        /// On received action handler.
        /// </summary>
        /// <param name="context">The current client context.</param>
        private void OnReceivedActionHandler(Nequeo.Net.Provider.Context context)
        {
            try
            {
                // Create the http context and set the headers.
                Nequeo.Net.Http.HttpContext httpContext = CreateHttpContext(context);

                // Get the headers from the stream and assign the request data.
                bool headersExist = Nequeo.Net.Http.Utility.SetRequestHeaders(httpContext, base.HeaderTimeout, base.MaximumReadLength);

                // If the event has been assigned.
                if (OnHttpContext != null)
                {
                    OnHttpContext(this, httpContext);
                }

                // Save the web context state objects.
                SaveWebContext(context, httpContext);
            }
            catch (Exception)
            {
                // Close the connection and release all resources used for communication.
                context.Close();
            }
        }
예제 #2
0
 /// <summary>
 /// Close and release all resources.
 /// </summary>
 public void Close()
 {
     // Close the connection.
     if (_context != null)
     {
         _context.Close();
     }
 }
예제 #3
0
        /// <summary>
        /// On received action handler.
        /// </summary>
        /// <param name="context">The current client context.</param>
        private void OnReceivedActionHandler(Nequeo.Net.Provider.Context context)
        {
            try
            {
                // Store data until all frame data has been read.
                if (Nequeo.Net.Http2.Utility.IsParseInitialFramePreamble(context.Request.Input, context.RequestBufferStore, _maxFrameBufferStore))
                {
                    // Create the http context and set the headers.
                    Nequeo.Net.Http2.HttpContext httpContext = CreateHttpContext(context);

                    // Get the headers from the stream and assign the request data.
                    bool canPassContext = false;
                    bool frameExist     = Nequeo.Net.Http2.Utility.ProcessFrameRequest(httpContext, out canPassContext,
                                                                                       base.HeaderTimeout, base.MaximumReadLength, context.RequestBufferStore);

                    // If frame exeist.
                    if (frameExist && canPassContext)
                    {
                        // If the event has been assigned.
                        if (OnHttpContext != null)
                        {
                            OnHttpContext(this, httpContext);
                        }

                        // Save the web context state objects.
                        SaveWebContext(context, httpContext);
                    }
                    else
                    {
                        // If some error has occured.
                        if (!frameExist)
                        {
                            throw new Exception("Frame not found.");
                        }
                    }
                }

                // If the maximum request buffer store has been reached then close the connection.
                if (context.RequestBufferStore.Length > _maxFrameBufferStore)
                {
                    throw new Exception("Maximum request buffer store has been reached.");
                }
            }
            catch (Exception)
            {
                // Close the connection and release all resources used for communication.
                context.Close();
            }
        }
예제 #4
0
        /// <summary>
        /// On received action handler.
        /// </summary>
        /// <param name="context">The current client context.</param>
        private void OnReceivedActionHandler(Nequeo.Net.Provider.Context context)
        {
            try
            {
                // Create the http context and set the headers.
                Nequeo.Net.Http2.HttpContext httpContext = CreateHttpContext(context);

                // Get the headers from the stream and assign the request data.
                bool canPassContext = false;
                bool frameExist     = Nequeo.Net.Http2.Utility.ProcessFrameRequest(httpContext, out canPassContext,
                                                                                   base.HeaderTimeout, base.MaximumReadLength);

                // If frame exists.
                if (frameExist && canPassContext)
                {
                    // If the event has been assigned.
                    if (OnHttpContext != null)
                    {
                        OnHttpContext(this, httpContext);
                    }

                    // Save the web context state objects.
                    SaveWebContext(context, httpContext);
                }
                else
                {
                    // If some error has occured.
                    if (!frameExist)
                    {
                        throw new Exception("Frame not found.");
                    }
                }
            }
            catch (Exception)
            {
                // Close the connection and release all resources used for communication.
                context.Close();
            }
        }
예제 #5
0
        /// <summary>
        /// On received action handler.
        /// </summary>
        /// <param name="context">The current server context.</param>
        private void OnReceivedActionHandler(Nequeo.Net.Provider.Context context)
        {
            try
            {
                // Create the web context and set the headers.
                Nequeo.Net.WebContext webContext = CreateWebContext(context);

                // If the event has been assigned.
                if (OnWebContext != null)
                {
                    OnWebContext(this, webContext);
                }

                // Save the web context state objects.
                SaveWebContext(context, webContext);
            }
            catch (Exception)
            {
                // Close the connection and release all resources used for communication.
                context.Close();
            }
        }
예제 #6
0
        /// <summary>
        /// On received action handler.
        /// </summary>
        /// <param name="context">The current client context.</param>
        private void OnReceivedActionHandler(Nequeo.Net.Provider.Context context)
        {
            try
            {
                // Store data until all headers have been read.
                if (Nequeo.Net.Utility.IsParse2CRLF(context.Request.Input, context.RequestBufferStore, _maxHeaderBufferStore))
                {
                    // Create the http context and set the headers.
                    Nequeo.Net.Http.HttpContext httpContext = CreateHttpContext(context);

                    // Get the headers from the stream and assign the request data.
                    bool headersExist = Nequeo.Net.Http.Utility.SetRequestHeaders(httpContext,
                                                                                  base.HeaderTimeout, base.MaximumReadLength, context.RequestBufferStore);

                    // If the event has been assigned.
                    if (OnHttpContext != null)
                    {
                        OnHttpContext(this, httpContext);
                    }

                    // Save the web context state objects.
                    SaveWebContext(context, httpContext);
                }

                // If the maximum request buffer store has been reached then close the connection.
                if (context.RequestBufferStore.Length > _maxHeaderBufferStore)
                {
                    throw new Exception("Maximum request buffer store has been reached.");
                }
            }
            catch (Exception)
            {
                // Close the connection and release all resources used for communication.
                context.Close();
            }
        }
예제 #7
0
        /// <summary>
        /// On received action handler.
        /// </summary>
        /// <param name="context">The current client context.</param>
        private void OnReceivedActionHandler(Nequeo.Net.Provider.Context context)
        {
            try
            {
                // Store data until all headers have been read.
                if (Nequeo.Net.Utility.IsParse2CRLF(context.Request.Input, context.RequestBufferStore, _maxHeaderBufferStore))
                {
                    // Create the web socket context and set the headers.
                    Nequeo.Net.WebSockets.WebSocketContext webSocketContext = CreateWebSocketContext(context);

                    // Get the headers from the stream and assign the request data.
                    bool headersExist = Nequeo.Net.WebSockets.Utility.SetRequestHeaders(webSocketContext,
                                                                                        base.HeaderTimeout, base.MaximumReadLength, context.RequestBufferStore);

                    // Create the response headers.
                    CreateResponseHeaders(webSocketContext);

                    // Make sure all handshaking has complete before continuing.
                    if (!webSocketContext.HandshakeComplete)
                    {
                        // Check to see if the request is a web socket.
                        CheckIfWebSocketRequest(webSocketContext);
                    }
                    else
                    {
                        // Indicate that all web sockets after handshaking
                        // is complete will run in async mode.
                        webSocketContext.IsAsyncMode = true;

                        // Create the central web socket context.
                        CentralWebSocketContext centralWebSocketContext = new CentralWebSocketContext(webSocketContext);
                        centralWebSocketContext.ConnectionID          = webSocketContext.ConnectionID;
                        centralWebSocketContext.Cookies               = webSocketContext.WebSocketRequest.Cookies;
                        centralWebSocketContext.Headers               = webSocketContext.WebSocketRequest.Headers;
                        centralWebSocketContext.IsAuthenticated       = webSocketContext.IsAuthenticated;
                        centralWebSocketContext.IsSecureConnection    = webSocketContext.IsSecureConnection;
                        centralWebSocketContext.SecWebSocketKey       = webSocketContext.WebSocketRequest.SecWebSocketKey;
                        centralWebSocketContext.SecWebSocketProtocols = webSocketContext.WebSocketRequest.SecWebSocketProtocols;
                        centralWebSocketContext.SecWebSocketVersion   = webSocketContext.WebSocketRequest.SecWebSocketVersion;
                        centralWebSocketContext.SessionID             = webSocketContext.SessionID;
                        centralWebSocketContext.SocketState           = webSocketContext.SocketState;
                        centralWebSocketContext.UniqueIdentifier      = webSocketContext.UniqueIdentifier;
                        centralWebSocketContext.Url  = webSocketContext.WebSocketRequest.Url;
                        centralWebSocketContext.User = webSocketContext.User;

                        // If the event has been assigned.
                        if (OnWebSocketContext != null)
                        {
                            OnWebSocketContext(this, centralWebSocketContext);
                        }

                        // Write the response to the client.
                        Nequeo.Net.WebSockets.WebSocketResponse response = webSocketContext.WebSocketResponse;
                        response.WriteWebSocketHeaders();

                        // Create and assign the web socket.
                        Nequeo.Net.WebSockets.WebSocket webSocket = new Nequeo.Net.WebSockets.WebSocket(centralWebSocketContext, response.ProtocolVersion);
                        centralWebSocketContext.WebSocket = webSocket;

                        // Save the web context state objects.
                        SaveWebContext(context, webSocketContext);
                    }
                }

                // If the maximum request buffer store has been reached then close the connection.
                if (context.RequestBufferStore.Length > _maxHeaderBufferStore)
                {
                    throw new Exception("Maximum request buffer store has been reached.");
                }
            }
            catch (Exception)
            {
                // Close the connection and release all resources used for communication.
                context.Close();
            }
        }