/// <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(); } }
/// <summary> /// Create the http context. /// </summary> /// <param name="context">The current client context.</param> /// <returns>The http context.</returns> private Nequeo.Net.Http2.HttpContext CreateHttpContext(Nequeo.Net.Provider.Context context) { // If the http context has not been assign to the state. if (context.State == null) { // Get the underlying web context. Nequeo.Net.WebContext webContext = CreateWebContext(context); // Create the new http context from the web context. Nequeo.Net.Http2.HttpContext httpContext = Nequeo.Net.Http2.HttpContext.CreateFrom(webContext, context.Request.Input, context.Response.Output); httpContext.UsePriorities = _usePriorities; httpContext.UseFlowControl = _useFlowControl; // Return the request context. context.State = httpContext; return(httpContext); } else { // Get the saved context. Nequeo.Net.Http2.HttpContext httpContext = (Nequeo.Net.Http2.HttpContext)context.State; return(httpContext); } }
/// <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(); } }
/// <summary> /// Create the http context. /// </summary> /// <param name="context">The current client context.</param> /// <returns>The http context.</returns> private Nequeo.Net.Http.HttpContext CreateHttpContext(Nequeo.Net.Provider.Context context) { // Get the underlying web context. Nequeo.Net.WebContext webContext = CreateWebContext(context); // Create the new http context from the web context. Nequeo.Net.Http.HttpContext httpContext = Nequeo.Net.Http.HttpContext.CreateFrom(webContext); // Assign response and request data. httpContext.HttpResponse = new HttpResponse(); httpContext.HttpRequest = new HttpRequest(); httpContext.HttpResponse.Output = webContext.WebResponse.Output; httpContext.HttpRequest.Input = webContext.WebRequest.Input; // Return the request context. return(httpContext); }
/// <summary> /// Create the web socket context. /// </summary> /// <param name="context">The current client context.</param> /// <returns>The web socket context.</returns> private Nequeo.Net.WebSockets.WebSocketContext CreateWebSocketContext(Nequeo.Net.Provider.Context context) { // Get the underlying web context. Nequeo.Net.WebContext webContext = CreateWebContext(context); // Create the new web socket context from the web context. Nequeo.Net.WebSockets.WebSocketContext webSocketContext = Nequeo.Net.WebSockets.WebSocketContext.CreateFrom(webContext); // Assign response and request data. webSocketContext.WebSocketResponse = new WebSocketResponse(); webSocketContext.WebSocketRequest = new WebSocketRequest(); webSocketContext.WebSocketResponse.Output = webContext.WebResponse.Output; webSocketContext.WebSocketRequest.Input = webContext.WebRequest.Input; // Return the request context. return(webSocketContext); }
/// <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(); } }
/// <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(); } }
/// <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(); } }
/// <summary> /// Inject the current context provider. /// </summary> /// <param name="context">The provider context.</param> public WebContext(Nequeo.Net.Provider.Context context) { _context = context; }
/// <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(); } }