public ScriptContext(IMiddlerContext middlerContext, ScriptContextMethods scriptContextMethods) { _middlerContext = middlerContext; _scriptContextMethods = scriptContextMethods; Request = new ScriptContextRequest(middlerContext.Request); Response = new ScriptContextResponse(middlerContext.Response); }
public void ExecuteRequest(IMiddlerContext middlerContext, IActionHelper actionHelper) { var rewriteTo = actionHelper.BuildPathFromRoutData(Parameters.RewriteTo); var isAbsolute = Uri.IsWellFormedUriString(rewriteTo, UriKind.Absolute); if (isAbsolute) { middlerContext.Request.Uri = new Uri(rewriteTo); } else { var builder = new UriBuilder(middlerContext.Request.Uri); builder.Query = null; if (rewriteTo.Contains("?")) { builder.Path = rewriteTo.Split("?")[0]; builder.Query = rewriteTo.Split("?")[1]; } else { builder.Path = rewriteTo; } middlerContext.Request.Uri = builder.Uri; } //middlerContext.ForwardBody(); //var nUrl = new UriBuilder(Parameters.RewriteTo); //builder.Path = Parameters.RewriteTo; }
public void ExecuteRequest(IMiddlerContext middlerContext, IActionHelper actionHelper) { var uri = new Uri(actionHelper.BuildPathFromRoutData(Parameters.RedirectTo)); if (Parameters.PreserveMethod) { middlerContext.Response.StatusCode = Parameters.Permanent ? StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect; } else { middlerContext.Response.StatusCode = Parameters.Permanent ? StatusCodes.Status301MovedPermanently : StatusCodes.Status302Found; } middlerContext.Response.Headers["Location"] = uri.AbsoluteUri; }
public async Task ExecuteRequestAsync(IMiddlerContext middlerContext) { IScriptEngine scriptEngine = _serviceProvider.GetRequiredNamedService <IScriptEngine>(Parameters.Language); var compile = scriptEngine.NeedsCompiledScript && (!string.IsNullOrEmpty(Parameters.SourceCode) && string.IsNullOrWhiteSpace(Parameters.CompiledCode)); if (compile) { CompileScriptIfNeeded(); } var scriptContextMethods = new ScriptContextMethods(); //scriptContextMethods.SendResponse = () => //{ // Console.WriteLine("Test von Action"); // scriptEngine.Stop(); //}; var scriptContext = new ScriptContext(middlerContext, scriptContextMethods); scriptContext.Terminating = Terminating; scriptEngine.SetValue("context", scriptContext); //scriptEngine.SetValue("m", new Environment(middlerContext.RequestServices.GetService<IVariablesRepository>())); try { await scriptEngine.ExecuteAsync(scriptEngine.NeedsCompiledScript?Parameters.CompiledCode : Parameters.SourceCode); //SendResponse(middlerContext.Response, scriptContext); } catch (Exception e) { throw e; //await httpContext.BadRequest(e.GetBaseException().Message); } Terminating = scriptContext.Terminating; }
public async Task ExecuteRequestAsync(IMiddlerContext middlerContext) { IScriptEngine scriptEngine = GetScriptEngine(); var scriptContextMethods = new ScriptContextMethods(); scriptContextMethods.SendResponse = () => { Console.WriteLine("Test von Action"); scriptEngine.Stop(); }; var scriptContext = new ScriptContext(middlerContext, scriptContextMethods); scriptContext.Terminating = Terminating; scriptEngine.Initialize(); scriptEngine.SetValue("context", scriptContext); scriptEngine.SetValue("m", new Environment(middlerContext.RequestServices.GetService <VariableStore>())); try { await scriptEngine.Execute(scriptEngine.NeedsCompiledScript?Parameters.CompiledCode : Parameters.SourceCode); //SendResponse(middlerContext.Response, scriptContext); } catch (Exception e) { throw e; //await httpContext.BadRequest(e.GetBaseException().Message); } Terminating = scriptContext.Terminating; }
public void ExecuteResponse(IMiddlerContext middlerContext) { middlerContext.Response.Headers["TestHeader"] = "irgendwas"; }