/// <summary> /// Initialize /// </summary> /// <param name="parentContext">Parent context</param> /// <param name="coreRequest">Original http request</param> public CoreHttpRequestWrapper( CoreHttpContextWrapper parentContext, HttpRequest coreRequest) { ParentContext = parentContext; CoreRequest = coreRequest; ContainsFormValues = new Lazy <bool>(() => { var contentType = (ContentType ?? "").Split(';')[0]; return(contentType == "application/x-www-form-urlencoded" || contentType == "multipart/form-data"); }); }
/// <summary> /// Configure application /// </summary> public virtual void Configure(IApplicationBuilder app, IApplicationLifetime lifetime) { try { // Initialize application Application.Ioc.RegisterMany <CoreWebsiteStopper>(ReuseType.Singleton); Application.Initialize(GetWebsiteRootDirectory()); Application.Ioc.RegisterInstance(lifetime); // Configure middlewares ConfigureMiddlewares(app); } catch { // Stop application after error reported var thread = new Thread(() => { Thread.Sleep(3000); lifetime.StopApplication(); }); thread.IsBackground = true; thread.Start(); throw; } // Set request handler, it will running in thread pool // It can't throw any exception otherwise application will get killed app.Run(coreContext => Task.Run(() => { var context = new CoreHttpContextWrapper(coreContext); try { // Handle request Application.OnRequest(context); } catch (CoreHttpResponseEndException) { // Success } catch (Exception ex) { // Error try { Application.OnError(context, ex); } catch (CoreHttpResponseEndException) { // Handle error success } catch (Exception) { // Handle error failed } } })); }
/// <summary> /// Initialize /// </summary> /// <param name="parentContext">Parent http context</param> /// <param name="coreResponse">Original http response</param> public CoreHttpResponseWrapper( CoreHttpContextWrapper parentContext, HttpResponse coreResponse) { ParentContext = parentContext; CoreResponse = coreResponse; }