protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state) { IHttpHandler httpHandler = GetHttpHandler(httpContext); IHttpAsyncHandler httpAsyncHandler = httpHandler as IHttpAsyncHandler; if (httpAsyncHandler != null) { // asynchronous handler // Ensure delegates continue to use the C# Compiler static delegate caching optimization. BeginInvokeDelegate <IHttpAsyncHandler> beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState, IHttpAsyncHandler innerHandler) { return(innerHandler.BeginProcessRequest(HttpContext.Current, asyncCallback, asyncState)); }; EndInvokeVoidDelegate <IHttpAsyncHandler> endDelegate = delegate(IAsyncResult asyncResult, IHttpAsyncHandler innerHandler) { innerHandler.EndProcessRequest(asyncResult); }; return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, httpAsyncHandler, _processRequestTag)); } else { // synchronous handler Action action = delegate { httpHandler.ProcessRequest(HttpContext.Current); }; return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag)); } }
protected override IAsyncResult GetAsyncResult (Func<Task> taskFactory, AsyncCallback callback, object state) { Assert.IsNull (handler, "GetAsyncResult#A01"); handler = new TestHttpTaskAsyncHandler (taskFactory, expectedContext); return handler.BeginProcessRequest (expectedContext, callback, state); }
/// <summary> /// Creates an asynchronous HTTP host. /// </summary> /// <param name="handler">Handler to serve requests with</param> /// <param name="accepts"> /// Higher values mean more connections can be maintained yet at a much slower average response time; fewer connections will be rejected. /// Lower values mean less connections can be maintained yet at a much faster average response time; more connections will be rejected. /// </param> public HttpAsyncHost(IHttpAsyncHandler handler, int accepts = 4) { _handler = handler ?? NullHttpAsyncHandler.Default; _listener = new HttpListener(); // Multiply by number of cores: _accepts = accepts * Environment.ProcessorCount; }
protected override IAsyncResult GetAsyncResult(Func <Task> taskFactory, AsyncCallback callback, object state) { Assert.IsNull(handler, "GetAsyncResult#A01"); handler = new TestHttpTaskAsyncHandler(taskFactory, expectedContext); return(handler.BeginProcessRequest(expectedContext, callback, state)); }
public HttpAsyncHandler(IWorkContextAccessor workContextAccessor, IHttpHandler httpHandler, Func <IDictionary <string, object>, Task> env) { _workContextAccessor = workContextAccessor; _httpAsyncHandler = httpHandler as IHttpAsyncHandler; _pipeline = env; }
protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state) { IHttpHandler requestHandler = GetHttpHandler(httpContext); BeginProcessRequestDelegate beginCallback; AsyncCallback endCallback; IHttpAsyncHandler asyncHandler = requestHandler as IHttpAsyncHandler; if (asyncHandler != null) { beginCallback = asyncHandler.BeginProcessRequest; endCallback = asyncHandler.EndProcessRequest; } else { // execute synchronous IHttpHandler asynchronously ProcessRequestDelegate processRequestDelegate = hc => SynchronizationContext.Sync(() => requestHandler.ProcessRequest(hc)); beginCallback = processRequestDelegate.BeginInvoke; endCallback = processRequestDelegate.EndInvoke; } return(AsyncResultWrapper.Wrap(callback, state, (innerCallback, innerState) => beginCallback(HttpContext.Current, innerCallback, innerState), endCallback, _processRequestTag)); }
protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state) { IHttpHandler httpHandler = GetHttpHandler(httpContext); IHttpAsyncHandler httpAsyncHandler = httpHandler as IHttpAsyncHandler; if (httpAsyncHandler != null) { // asynchronous handler BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState) { return(httpAsyncHandler.BeginProcessRequest(HttpContext.Current, asyncCallback, asyncState)); }; EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult) { httpAsyncHandler.EndProcessRequest(asyncResult); }; return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _processRequestTag)); } else { // synchronous handler Action action = delegate { httpHandler.ProcessRequest(HttpContext.Current); }; return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag)); } }
/// <summary> /// Handles GET and HEAD request. /// </summary> /// <param name="context">Instace of <see cref="DavContextBaseAsync"/>.</param> /// <param name="item">Instance of <see cref="IHierarchyItemAsync"/> which was returned by /// <see cref="DavContextBaseAsync.GetHierarchyItemAsync"/> for this request.</param> public async Task ProcessRequestAsync(DavContextBaseAsync context, IHierarchyItemAsync item) { string urlPath = context.Request.RawUrl.Substring(context.Request.ApplicationPath.TrimEnd('/').Length); if (item is IItemCollectionAsync) { // In case of GET requests to WebDAV folders we serve a web page to display // any information about this server and how to use it. // Remember to call EnsureBeforeResponseWasCalledAsync here if your context implementation // makes some useful things in BeforeResponseAsync. await context.EnsureBeforeResponseWasCalledAsync(); IHttpAsyncHandler page = (IHttpAsyncHandler)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath( "~/MyCustomHandlerPage.aspx", typeof(MyCustomHandlerPage)); if (Type.GetType("Mono.Runtime") != null) { page.ProcessRequest(HttpContext.Current); } else { // Here we call BeginProcessRequest instead of ProcessRequest to start an async page execution and be able to call RegisterAsyncTask if required. // To call APM method (Begin/End) from TAP method (Task/async/await) the Task.FromAsync must be used. await Task.Factory.FromAsync(page.BeginProcessRequest, page.EndProcessRequest, HttpContext.Current, null); } } else { await OriginalHandler.ProcessRequestAsync(context, item); } }
/// <summary> /// Creates an asynchronous HTTP host. /// </summary> /// <param name="handler">Handler to serve requests with</param> /// <param name="accepts"> /// Higher values mean more connections can be maintained yet at a much slower average response time; fewer connections will be rejected. /// Lower values mean less connections can be maintained yet at a much faster average response time; more connections will be rejected. /// </param> public HttpAsyncHost(IHttpAsyncHandler handler, int accepts = 1) //public HttpAsyncHost(int accepts = 4) { _handler = handler ?? throw new ArgumentNullException("handler"); // NOTE: *** WE SHOULD NOT HAVE MORE THAN 1 THREAD FOR CASTER BECAUSE UI INPUT NEEDS TO BE SYNCRONOUS *** _accepts = accepts; }
public static IHttpHandler Wrap(IHttpHandler handler) { IHttpAsyncHandler asyncHandler = (handler as IHttpAsyncHandler); return((asyncHandler != null) ? new HttpAsyncHandlerWrapper(asyncHandler) : new HttpSyncHandlerWrapper(handler)); }
/// <summary> /// Executes controller based on route data. /// </summary> /// <param name="context"></param> /// <param name="routeData"></param> /// <returns></returns> private async Task ExecuteController(HttpContext context, RouteData routeData) { var wrapper = new HttpContextWrapper(context); MvcHandler handler = new MvcHandler(new RequestContext(wrapper, routeData)); IHttpAsyncHandler asyncHandler = ((IHttpAsyncHandler)handler); await Task.Factory.FromAsync(asyncHandler.BeginProcessRequest, asyncHandler.EndProcessRequest, context, null); }
public static IHttpHandler WrapForServerExecute(IHttpHandler httpHandler) { // Since Server.Execute() doesn't propagate HttpExceptions where the status code is // anything other than 500, we need to wrap these exceptions ourselves. IHttpAsyncHandler asyncHandler = httpHandler as IHttpAsyncHandler; return((asyncHandler != null) ? new ServerExecuteHttpHandlerAsyncWrapper(asyncHandler) : new ServerExecuteHttpHandlerWrapper(httpHandler)); }
/// <summary> /// Creates an asynchronous HTTP host. /// </summary> /// <param name="handler">Handler to serve requests with</param> /// <param name="accepts"> /// Higher values mean more connections can be maintained yet at a much slower average response time; fewer connections will be rejected. /// Lower values mean less connections can be maintained yet at a much faster average response time; more connections will be rejected. /// </param> public HttpAsyncHost(IHttpAsyncHandler handler, int accepts = 1) { SetStatus(HttpAsyncHostStatus.Uninitialised); _handler = handler ?? throw new ArgumentNullException("handler"); _accepts = accepts; SetStatus(HttpAsyncHostStatus.Initialised); }
/// <summary> /// Creates an asynchronous HTTP host. /// </summary> /// <param name="handler">Handler to serve requests with</param> /// <param name="accepts"> /// Higher values mean more connections can be maintained yet at a much slower average response time; fewer connections will be rejected. /// Lower values mean less connections can be maintained yet at a much faster average response time; more connections will be rejected. /// </param> public HttpAsyncHost(IHttpAsyncHandler handler, int accepts = 4) { _handler = handler ?? NullHttpAsyncHandler.Default; _listener = new HttpListener(); // Multiply by number of cores: _accepts = accepts * Environment.ProcessorCount; log_timer = new Timer(WriteLog, null, 300000, 300000); HttpCdnAddress = new HttpCDNAddress(); }
public static IHttpHandler WrapForServerExecute(IHttpHandler httpHandler) { IHttpAsyncHandler httpAsyncHandler = httpHandler as IHttpAsyncHandler; if (httpAsyncHandler == null) { return(new HttpHandlerUtil.ServerExecuteHttpHandlerWrapper(httpHandler)); } return(new HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper(httpAsyncHandler)); }
protected override void TestSetUp() { base.TestSetUp(); handler = null; var request = new HttpRequest(string.Empty, "http://localhost/", string.Empty); var response = new HttpResponse(TextWriter.Null); expectedContext = new HttpContext(request, response); }
public WebSocketAwareHttpHandler() { var path = HostingEnvironment.ApplicationVirtualPath; var webConfig = WebConfigurationManager.OpenWebConfiguration(path); // Parse WebConfig to a HandlerConfig object, then read the inner handler type. // We'll get a default if no custom handler has been specified. var handlerConfig = new HandlerConfig(webConfig); var handlerType = handlerConfig.HandlerType; // Create the inner handler. Assume it has a default constructor. _handler = (IHttpAsyncHandler)Activator.CreateInstance(handlerType); }
public void WrapForServerExecute_EndProcessRequest_DelegatesCorrectly() { // Arrange IAsyncResult asyncResult = new Mock <IAsyncResult>().Object; HttpContext httpContext = GetHttpContext(); Mock <IHttpAsyncHandler> mockHttpHandler = new Mock <IHttpAsyncHandler>(); mockHttpHandler.Setup(o => o.EndProcessRequest(asyncResult)).Verifiable(); IHttpAsyncHandler wrapper = (IHttpAsyncHandler)HttpHandlerUtil.WrapForServerExecute(mockHttpHandler.Object); // Act wrapper.EndProcessRequest(asyncResult); // Assert mockHttpHandler.Verify(); }
public void WrapForServerExecute_BeginProcessRequest_DelegatesCorrectly() { // Arrange IAsyncResult expectedResult = new Mock <IAsyncResult>().Object; AsyncCallback cb = delegate { }; HttpContext httpContext = GetHttpContext(); Mock <IHttpAsyncHandler> mockHttpHandler = new Mock <IHttpAsyncHandler>(); mockHttpHandler.Setup(o => o.BeginProcessRequest(httpContext, cb, "extraData")).Returns(expectedResult); IHttpAsyncHandler wrapper = (IHttpAsyncHandler)HttpHandlerUtil.WrapForServerExecute(mockHttpHandler.Object); // Act IAsyncResult actualResult = wrapper.BeginProcessRequest(httpContext, cb, "extraData"); // Assert Assert.Equal(expectedResult, actualResult); }
/// <summary> /// Handles GET and HEAD request. /// </summary> /// <param name="context">Instace of <see cref="DavContextBaseAsync"/>.</param> /// <param name="item">Instance of <see cref="IHierarchyItemAsync"/> which was returned by /// <see cref="DavContextBaseAsync.GetHierarchyItemAsync"/> for this request.</param> public void ProcessRequest(DavContextBase context, IHierarchyItem item) { if (item is IItemCollection) { // In case of GET requests to WebDAV folders we serve a web page to display // any information about this server and how to use it. // Remember to call EnsureBeforeResponseWasCalled here if your context implementation // makes some useful things in BeforeResponseAsync. context.EnsureBeforeResponseWasCalled(); IHttpAsyncHandler page = (IHttpAsyncHandler)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath( "~/MyCustomHandlerPage.aspx", typeof(MyCustomHandlerPage)); page.ProcessRequest(HttpContext.Current); } else { OriginalHandler.ProcessRequest(context, item); } }
protected virtual IAsyncResult BeginProcessRequest( HttpContextBase context, AsyncCallback callback, object state) { IHttpHandler handler = GetHttpHandler(context); IHttpAsyncHandler asyncHandler = (handler as IHttpAsyncHandler); if (asyncHandler == null) { Action action = delegate { handler.ProcessRequest(context.Unwrap()); }; return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _tag)); } BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState) { return(asyncHandler.BeginProcessRequest(context.Unwrap(), asyncCallback, asyncState)); }; EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult) { asyncHandler.EndProcessRequest(asyncResult); }; return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _tag)); }
protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state) { BeginInvokeDelegate delegate4 = null; EndInvokeDelegate delegate5 = null; Action action2 = null; IHttpHandler httpHandler = GetHttpHandler(httpContext); IHttpAsyncHandler httpAsyncHandler = httpHandler as IHttpAsyncHandler; if (httpAsyncHandler != null) { if (delegate4 == null) { delegate4 = (asyncCallback, asyncState) => httpAsyncHandler.BeginProcessRequest(HttpContext.Current, asyncCallback, asyncState); } BeginInvokeDelegate beginDelegate = delegate4; if (delegate5 == null) { delegate5 = delegate(IAsyncResult asyncResult) { httpAsyncHandler.EndProcessRequest(asyncResult); }; } EndInvokeDelegate endDelegate = delegate5; return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _processRequestTag)); } if (action2 == null) { action2 = delegate { httpHandler.ProcessRequest(HttpContext.Current); } } ; Action action = action2; return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag)); }
public HostContext(IHttpAsyncHost host, IHttpAsyncHandler handler) { Host = host; Handler = handler; }
internal void Execute(IHttpHandler handler, TextWriter writer, bool preserveForm, string exePath, string queryString, bool isTransfer, bool isInclude) { #if !TARGET_J2EE // If the target handler is not Page, the transfer must not occur. // InTransit == true means we're being called from Transfer bool is_static = (handler is StaticFileHandler); if (isTransfer && !(handler is Page) && !is_static) { throw new HttpException("Transfer is only allowed to .aspx and static files"); } #endif HttpRequest request = context.Request; string oldQuery = request.QueryStringRaw; if (queryString != null) { request.QueryStringRaw = queryString; } else if (!preserveForm) { request.QueryStringRaw = String.Empty; } HttpResponse response = context.Response; WebROCollection oldForm = request.Form as WebROCollection; if (!preserveForm) { request.SetForm(new WebROCollection()); } TextWriter output = writer; if (output == null) { output = response.Output; } TextWriter previous = response.SetTextWriter(output); string oldExePath = request.CurrentExecutionFilePath; bool oldIsInclude = context.IsProcessingInclude; try { context.PushHandler(handler); if (is_static) // Not sure if this should apply to Page too { request.SetFilePath(exePath); } request.SetCurrentExePath(exePath); context.IsProcessingInclude = isInclude; if (!(handler is IHttpAsyncHandler)) { handler.ProcessRequest(context); } else { IHttpAsyncHandler asyncHandler = (IHttpAsyncHandler)handler; IAsyncResult ar = asyncHandler.BeginProcessRequest(context, null, null); WaitHandle asyncWaitHandle = ar != null ? ar.AsyncWaitHandle : null; if (asyncWaitHandle != null) { asyncWaitHandle.WaitOne(); } asyncHandler.EndProcessRequest(ar); } } finally { if (oldQuery != request.QueryStringRaw) { if (oldQuery != null && oldQuery.Length > 0) { oldQuery = oldQuery.Substring(1); // Ignore initial '?' request.QueryStringRaw = oldQuery; // which is added here. } else { request.QueryStringRaw = String.Empty; } } response.SetTextWriter(previous); if (!preserveForm) { request.SetForm(oldForm); } context.PopHandler(); request.SetCurrentExePath(oldExePath); context.IsProcessingInclude = oldIsInclude; } }
public HttpAsyncHandler(IWorkContextAccessor workContextAccessor, IHttpHandler httpHandler, Func<IDictionary<string, object>, Task> env) { _workContextAccessor = workContextAccessor; _httpAsyncHandler = httpHandler as IHttpAsyncHandler; _pipeline = env; }
void HttpApplication.IExecutionStep.Execute() { HttpContext context = this._application.Context; IHttpHandler handler = context.Handler; if (EtwTrace.IsTraceEnabled(4, 4)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_ENTER, context.WorkerRequest); } if ((handler != null) && HttpRuntime.UseIntegratedPipeline) { IIS7WorkerRequest workerRequest = context.WorkerRequest as IIS7WorkerRequest; if ((workerRequest != null) && workerRequest.IsHandlerExecutionDenied()) { this._sync = true; HttpException exception = new HttpException(0x193, System.Web.SR.GetString("Handler_access_denied")); exception.SetFormatter(new PageForbiddenErrorFormatter(context.Request.Path, System.Web.SR.GetString("Handler_access_denied"))); throw exception; } } if (handler == null) { this._sync = true; } else if (handler is IHttpAsyncHandler) { IHttpAsyncHandler handler2 = (IHttpAsyncHandler) handler; this._sync = false; this._handler = handler2; IAsyncResult result = handler2.BeginProcessRequest(context, this._completionCallback, null); if (result.CompletedSynchronously) { this._sync = true; this._handler = null; try { handler2.EndProcessRequest(result); } finally { context.Response.GenerateResponseHeadersForHandler(); } if (EtwTrace.IsTraceEnabled(4, 4)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); } } } else { this._sync = true; context.SyncContext.SetSyncCaller(); try { handler.ProcessRequest(context); } finally { context.SyncContext.ResetSyncCaller(); if (EtwTrace.IsTraceEnabled(4, 4)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); } context.Response.GenerateResponseHeadersForHandler(); } } }
private void OnAsyncHandlerCompletion(IAsyncResult ar) { if (ar.CompletedSynchronously) { // Synchronous completions will be handled by IExecutionStep.Execute. return; } // This IAsyncResult may actually have completed synchronously (we might be on the same thread // which called IExecutionStep.Execute) even if CompletedSynchronously = false. Regardless, // we should invoke the End* method on the same thread that invoked this callback, as some // applications use TLS instead of the IAsyncResult object itself to convey state information. HttpContext context = _application.Context; Exception error = null; // The asynchronous step has completed, so we should disallow further // async operations until the next step. context.SyncContext.ProhibitVoidAsyncOperations(); try { try { _handler.EndProcessRequest(ar); } finally { SuppressPostEndRequestIfNecessary(context); // In Integrated mode, generate the necessary response headers // after the ASP.NET handler runs. If EndProcessRequest throws, // the headers will be generated by ReportRuntimeError context.Response.GenerateResponseHeadersForHandler(); } } catch (Exception e) { if (e is ThreadAbortException || e.InnerException != null && e.InnerException is ThreadAbortException) { // Response.End happened during async operation _application.CompleteRequest(); } else { error = e; } } bool shouldCallResumeSteps = _asyncStepCompletionInfo.RegisterAsyncCompletion(error); if (!shouldCallResumeSteps) { return; } if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Page)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); _handler = null; // not to remember // re-set start time after an async completion (see VSWhidbey 231010) context.SetStartTime(); // Assert to disregard the user code up the stack if (HttpRuntime.IsLegacyCas) { ResumeStepsWithAssert(error); } else { ResumeSteps(error); } }
public static void PrepareRequestTo(string controller, string action) { var routeHandler = new AsyncMvcRouteHandler(); var httpContextBase = new Mock<HttpContextBase>(); var sessionState = new Mock<HttpSessionStateBase>(); var writer = new StringWriter(); var controllerFactory = new Mock<IControllerFactory>(); var request = new Mock<HttpRequestBase>(); var routeData = new RouteData(); routeData.Values["controller"] = controller; routeData.Values["action"] = action; httpContextBase.ExpectGet(x => x.Session).Returns(sessionState); httpContextBase.ExpectGet(x => x.Request).Returns(request); controllerFactory.Expect(x => x.CreateController(Arg.IsAny<RequestContext>(), controller)).Returns(new TestController()); ControllerBuilder.Current.SetControllerFactory(controllerFactory.Object); httpContext = new HttpContext(new HttpRequest("foo", "http://foo", "foo"), new HttpResponse(writer)); CallContext.HostContext = httpContext; var requestContext = new RequestContext(httpContextBase, routeData); httpHandler = (IHttpAsyncHandler)routeHandler.GetHttpHandler(requestContext); }
public MvcReadOnlySessionHandler(IHttpAsyncHandler originalHandler) : base(originalHandler) { }
private void OnAsyncHandlerCompletion(IAsyncResult ar) { if (!ar.CompletedSynchronously) { HttpContext context = this._application.Context; Exception error = null; try { try { this._handler.EndProcessRequest(ar); } finally { context.Response.GenerateResponseHeadersForHandler(); } } catch (Exception exception2) { if ((exception2 is ThreadAbortException) || ((exception2.InnerException != null) && (exception2.InnerException is ThreadAbortException))) { this._application.CompleteRequest(); } else { error = exception2; } } if (EtwTrace.IsTraceEnabled(4, 4)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); } this._handler = null; context.SetStartTime(); if (HttpRuntime.IsLegacyCas) { this.ResumeStepsWithAssert(error); } else { this.ResumeSteps(error); } } }
private void OnAsyncReady (IAsyncResult ar) { if (ar.CompletedSynchronously) return; Exception error = null; try { // Invoke end handler _handler.EndProcessRequest(ar); } catch (Exception exc) { // Flow this error to the next state (handle during state execution) error = exc; } _handler = null; _app._state.ExecuteNextAsync (error); }
static void Process(HttpWorkerRequest req) { bool error = false; #if TARGET_J2EE HttpContext context = HttpContext.Current; if (context == null) { context = new HttpContext(req); } else { context.SetWorkerRequest(req); } #else if (firstRun) { firstRun = false; if (initialException != null) { FinishWithException(req, HttpException.NewWithCode("Initial exception", initialException, WebEventCodes.RuntimeErrorRequestAbort)); error = true; } SetupOfflineWatch(); } HttpContext context = new HttpContext(req); #endif HttpContext.Current = context; #if !TARGET_J2EE if (AppIsOffline(context)) { return; } #endif // // Get application instance (create or reuse an instance of the correct class) // HttpApplication app = null; if (!error) { try { app = HttpApplicationFactory.GetApplication(context); } catch (Exception e) { FinishWithException(req, HttpException.NewWithCode(String.Empty, e, WebEventCodes.RuntimeErrorRequestAbort)); error = true; } } if (error) { context.Request.ReleaseResources(); context.Response.ReleaseResources(); HttpContext.Current = null; } else { context.ApplicationInstance = app; req.SetEndOfSendNotification(end_of_send_cb, context); // // Ask application to service the request // #if TARGET_J2EE IHttpAsyncHandler ihah = app; if (context.Handler == null) { ihah.BeginProcessRequest(context, new AsyncCallback(request_processed), context); } else { app.Tick(); } //ihh.ProcessRequest (context); IHttpExtendedHandler extHandler = context.Handler as IHttpExtendedHandler; if (extHandler != null && !extHandler.IsCompleted) { return; } if (context.Error is UnifyRequestException) { return; } ihah.EndProcessRequest(null); #else IHttpHandler ihh = app; // IAsyncResult appiar = ihah.BeginProcessRequest (context, new AsyncCallback (request_processed), context); // ihah.EndProcessRequest (appiar); ihh.ProcessRequest(context); #endif HttpApplicationFactory.Recycle(app); } }
public static IHttpHandler WrapForServerExecute(IHttpHandler httpHandler) { IHttpAsyncHandler asyncHandler = httpHandler as IHttpAsyncHandler; return((asyncHandler != null) ? new ServerExecuteHttpHandlerAsyncWrapper(asyncHandler) : new ServerExecuteHttpHandlerWrapper(httpHandler)); }
public HttpAsyncHandler(IWorkContextAccessor containerProvider, IHttpAsyncHandler httpAsyncHandler) : base(containerProvider, httpAsyncHandler) { _httpAsyncHandler = httpAsyncHandler; }
/// <summary> /// /// </summary> protected GameHttpHost(IHttpAsyncHandler handler) { listenUrls = new List<string>(); httpListener = new HttpAsyncHost(handler, 16); }
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback callback, object state) { _handler = GetHttpHandler(context); return(_handler.BeginProcessRequest(context, callback, state)); }
protected override void TestSetUp () { base.TestSetUp (); handler = null; var request = new HttpRequest (string.Empty, "http://localhost/", string.Empty); var response = new HttpResponse (TextWriter.Null); expectedContext = new HttpContext (request, response); }
void IExecutionStep.Execute() { HttpContext context = _application.Context; IHttpHandler handler = context.Handler; if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Page)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_ENTER, context.WorkerRequest); if (handler != null && HttpRuntime.UseIntegratedPipeline) { IIS7WorkerRequest wr = context.WorkerRequest as IIS7WorkerRequest; if (wr != null && wr.IsHandlerExecutionDenied()) { _sync = true; HttpException error = new HttpException(403, SR.GetString(SR.Handler_access_denied)); error.SetFormatter(new PageForbiddenErrorFormatter(context.Request.Path, SR.GetString(SR.Handler_access_denied))); throw error; } } if (handler == null) { _sync = true; } else if (handler is IHttpAsyncHandler) { // asynchronous handler IHttpAsyncHandler asyncHandler = (IHttpAsyncHandler)handler; _sync = false; _handler = asyncHandler; // Instrument the BeginProcessRequest method if AppVerifier is enabled. // If AppVerifier not enabled, we just get back the original delegate to BeginProcessRequest uninstrumented. var beginProcessRequestDelegate = AppVerifier.WrapBeginMethod<HttpContext>(_application, asyncHandler.BeginProcessRequest); _asyncStepCompletionInfo.Reset(); context.SyncContext.AllowVoidAsyncOperations(); IAsyncResult ar; try { ar = beginProcessRequestDelegate(context, _completionCallback, null); } catch { // The asynchronous step has completed, so we should disallow further // async operations until the next step. context.SyncContext.ProhibitVoidAsyncOperations(); throw; } bool operationCompleted; bool mustCallEndHandler; _asyncStepCompletionInfo.RegisterBeginUnwound(ar, out operationCompleted, out mustCallEndHandler); if (operationCompleted) { _sync = true; _handler = null; // not to remember // The asynchronous step has completed, so we should disallow further // async operations until the next step. context.SyncContext.ProhibitVoidAsyncOperations(); try { if (mustCallEndHandler) { asyncHandler.EndProcessRequest(ar); } _asyncStepCompletionInfo.ReportError(); } finally { SuppressPostEndRequestIfNecessary(context); // In Integrated mode, generate the necessary response headers // after the ASP.NET handler runs context.Response.GenerateResponseHeadersForHandler(); } if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Page)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); } } else { // synchronous handler _sync = true; // disable async operations //_application.SyncContext.Disable(); // VSWhidbey 268772 - If a synchronous handler internally kicks off an asynchronous operation and waits (blocking) for that // operation to complete, the handler will deadlock since the asynchronous operation can't come back to the appropriate // thread to perform the completion. The solution below was only meant to be temporary but was accidentally left in the product // for v2.0 RTM, so it's now legacy behavior and cannot be changed. context.SyncContext.SetSyncCaller(); try { handler.ProcessRequest(context); } finally { context.SyncContext.ResetSyncCaller(); if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Page)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); SuppressPostEndRequestIfNecessary(context); // In Integrated mode, generate the necessary response headers // after the ASP.NET handler runs context.Response.GenerateResponseHeadersForHandler(); } } }
public ServerExecuteHttpHandlerAsyncWrapper(IHttpAsyncHandler httpHandler) : base(httpHandler) { this._httpHandler = httpHandler; }
public MvcDynamicSessionHandler(IHttpAsyncHandler originalHandler) { _originalHandler = originalHandler; }
/// <summary> /// /// </summary> protected GameHttpHost(IHttpAsyncHandler handler) { listenUrls = new List <string>(); httpListener = new HttpAsyncHost(handler, 16); }
public HttpAsyncHandler(ContainerProvider containerProvider, IHttpAsyncHandler httpAsyncHandler) : base(containerProvider, httpAsyncHandler) { _httpAsyncHandler = httpAsyncHandler; }
public AsyncHandlerWrapper(IHttpAsyncHandler httpAsyncHandler, IHttpHandlerFactory factory) : base(httpAsyncHandler, factory) { this.httpAsyncHandler = httpAsyncHandler; }
public void Execute () { IHttpHandler handler = _app.Context.Handler; if (handler == null) return; // Check if we can execute async if (handler is IHttpAsyncHandler) { _async = true; _handler = (IHttpAsyncHandler) handler; IAsyncResult ar = _handler.BeginProcessRequest (_app.Context, _callback, null); if (ar.CompletedSynchronously) { _async = false; _handler = null; ((IHttpAsyncHandler) handler).EndProcessRequest (ar); } } else { _async = false; // Sync handler handler.ProcessRequest (_app.Context); } }