/// <summary> /// Adds a handler for a specific virtual path /// </summary> /// <param name="hostName">The host name to use for request resolution (Virtual hosts are not currently supported)</param> /// <param name="virtualPath">The virtual path that will be routed to this handler ( e.g "/virdir1"</param> /// <param name="handler">The handler that will handle requests on this path</param> /// <param name="force">If set to true, the handler will replace any other handlers defined at the path, if false, an exception will /// be thrown if any handlers are already defined at the path</param> public void AddHandlerContext( string hostName, string virtualPath, IAdkHttpHandler handler, bool force ) { AdkHttpHandlerListeningContext contextHandler = new AdkHttpHandlerListeningContext( handler ); this.AddHandlerContext( hostName, virtualPath, contextHandler, force ); }
/// <summary> /// Adds a handler for a specific virtual path /// </summary> /// <param name="hostName">The host name to use for request resolution (Virtual hosts are not currently supported)</param> /// <param name="virtualPath">The virtual path that will be routed to this handler ( e.g "/virdir1"</param> /// <param name="handler">The handler that will handle requests on this path</param> /// <param name="force">If set to true, the handler will replace any other handlers defined at the path, if false, an exception will /// be thrown if any handlers are already defined at the path</param> public void AddHandlerContext(string hostName, string virtualPath, IAdkHttpHandler handler, bool force) { AdkHttpHandlerListeningContext contextHandler = new AdkHttpHandlerListeningContext(handler); this.AddHandlerContext(hostName, virtualPath, contextHandler, force); }
public void SetAnonymousHandler( IAdkHttpHandler handler ) { this.Listener.AnonymousHandler = handler; }
public AdkHttpHandlerListeningContext( IAdkHttpHandler handler ) { fHandler = handler; }
public AdkHttpHandlerListeningContext(IAdkHttpHandler handler) { fHandler = handler; }
public void SetAnonymousHandler(IAdkHttpHandler handler) { this.Listener.AnonymousHandler = handler; }
private void ProcessRequest(AdkHttpRequestContext context, AdkSocketConnection socket) { int aStart = Environment.TickCount; bool keepAlive = true; AdkHttpRequest request = context.Request; AdkHttpResponse response = context.Response; try { context.Request.Receive(socket); if (!context.Request.ReceiveComplete) { socket.UserData = context; return; } else { IAdkHttpHandler handler = fListener.GetHandlerForContext(request); handler.ProcessRequest(context); } } catch (AdkHttpException httpEx) { _logError(httpEx); response.Clear(); response.Status = httpEx.HttpExceptionCode; if ((int)httpEx.HttpExceptionCode > 499) { keepAlive = false; } response.AdditionalInfo = httpEx.GetType().FullName + " - " + httpEx.Message + " - " + httpEx.StackTrace; } catch (Exception ex) { keepAlive = false; _logError(ex); // TODO : Implement more verbose error output ( internalexceptions and such ) response.Clear(); response.Status = AdkHttpStatusCode.ServerError_500_Internal_Server_Error; response.AdditionalInfo = ex.GetType().FullName + " - " + ex.Message + " - " + ex.StackTrace; } // Clear out the context state because we are done with this request and the socket // may remain open for the next request socket.UserData = null; if (socket.Connected) { if (keepAlive) { keepAlive = ShouldKeepAlive(context.Request); } context.Response.Headers.Add("X-Powered-By", fListener.Server.Name); // Write the Response context.Response.AsyncFinishRequest(socket, context.Request, keepAlive); if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0 && fListener.Server.Log.IsDebugEnabled) { fListener.Server.Log.Info (string.Format ("Processed Request for {0}:{1} ( {2} ) in {3} milliseconds", this.ClientEndPoint.Address, this.ClientEndPoint.Port, context.Request.Path, (Environment.TickCount - aStart).ToString())); } if (!keepAlive) { socket.Close(); } } }