Reformat code
This commit is contained in:
@@ -9,19 +9,16 @@ namespace VAR.WebFormsCore.AspNetCore.Code;
|
||||
public class AspnetCoreWebContext : IWebContext
|
||||
{
|
||||
private readonly HttpContext _context;
|
||||
|
||||
public AspnetCoreWebContext(HttpContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
|
||||
public AspnetCoreWebContext(HttpContext context) { _context = context; }
|
||||
|
||||
public string RequestPath => _context.Request.Path;
|
||||
|
||||
public string RequestMethod => _context.Request.Method;
|
||||
|
||||
|
||||
private Dictionary<string, string?>? _requestHeader;
|
||||
|
||||
|
||||
public Dictionary<string, string?> RequestHeader
|
||||
{
|
||||
get
|
||||
@@ -54,7 +51,7 @@ public class AspnetCoreWebContext : IWebContext
|
||||
}
|
||||
|
||||
private Dictionary<string, string?>? _requestQuery;
|
||||
|
||||
|
||||
public Dictionary<string, string?> RequestQuery
|
||||
{
|
||||
get
|
||||
@@ -68,9 +65,9 @@ public class AspnetCoreWebContext : IWebContext
|
||||
return _requestQuery;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<string, string?>? _requestForm;
|
||||
|
||||
|
||||
public Dictionary<string, string?> RequestForm
|
||||
{
|
||||
get
|
||||
@@ -82,69 +79,51 @@ public class AspnetCoreWebContext : IWebContext
|
||||
_requestForm = _context.Request.Form
|
||||
.ToDictionary(p => p.Key, p => p.Value[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_requestForm = new Dictionary<string, string?>();
|
||||
}
|
||||
else { _requestForm = new Dictionary<string, string?>(); }
|
||||
}
|
||||
|
||||
return _requestForm;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResponseWrite(string text)
|
||||
{
|
||||
_context.Response.WriteAsync(text).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public void ResponseWrite(string text) { _context.Response.WriteAsync(text).GetAwaiter().GetResult(); }
|
||||
|
||||
public void ResponseWriteBin(byte[] content)
|
||||
{
|
||||
_context.Response.Body.WriteAsync(content).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public void ResponseFlush()
|
||||
{
|
||||
_context.Response.Body.FlushAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
public void ResponseFlush() { _context.Response.Body.FlushAsync().GetAwaiter().GetResult(); }
|
||||
|
||||
public void ResponseRedirect(string url)
|
||||
{
|
||||
_context.Response.Redirect(url);
|
||||
}
|
||||
public void ResponseRedirect(string url) { _context.Response.Redirect(url); }
|
||||
|
||||
public void AddResponseCookie(string cookieName, string value, DateTime? expiration = null)
|
||||
{
|
||||
_context.Response.Cookies.Append(
|
||||
key: cookieName,
|
||||
value: value,
|
||||
options: new CookieOptions {Expires = expiration,}
|
||||
options: new CookieOptions { Expires = expiration, }
|
||||
);
|
||||
}
|
||||
|
||||
public void DelResponseCookie(string cookieName)
|
||||
{
|
||||
_context.Response.Cookies.Delete(cookieName);
|
||||
}
|
||||
public void DelResponseCookie(string cookieName) { _context.Response.Cookies.Delete(cookieName); }
|
||||
|
||||
public bool ResponseHasStarted => _context.Response.HasStarted;
|
||||
|
||||
|
||||
public int ResponseStatusCode
|
||||
{
|
||||
get => _context.Response.StatusCode;
|
||||
set => _context.Response.StatusCode = value;
|
||||
}
|
||||
|
||||
|
||||
public string? ResponseContentType
|
||||
{
|
||||
get => _context.Response.ContentType;
|
||||
set => _context.Response.ContentType = value;
|
||||
}
|
||||
|
||||
public void SetResponseHeader(string key, string value)
|
||||
{
|
||||
_context.Response.Headers.SafeSet(key, value);
|
||||
}
|
||||
|
||||
public void SetResponseHeader(string key, string value) { _context.Response.Headers.SafeSet(key, value); }
|
||||
|
||||
public void PrepareCacheableResponse()
|
||||
{
|
||||
const int secondsInDay = 86400;
|
||||
@@ -161,5 +140,4 @@ public class AspnetCoreWebContext : IWebContext
|
||||
.ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
|
||||
_context.Response.Headers.SafeSet("Expires", $"{expireDate} GMT");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace VAR.WebFormsCore.AspNetCore.Code;
|
||||
public class GlobalRouterMiddleware
|
||||
{
|
||||
private readonly GlobalRouter _globalRouter = new();
|
||||
|
||||
|
||||
public GlobalRouterMiddleware(RequestDelegate next, IWebHostEnvironment env)
|
||||
{
|
||||
ServerHelpers.SetContentRoot(env.ContentRootPath);
|
||||
@@ -26,7 +26,7 @@ public class GlobalRouterMiddleware
|
||||
httpContext.Response.Headers.SafeSet("X-XSS-Protection", "1; mode=block");
|
||||
|
||||
IWebContext webContext = new AspnetCoreWebContext(httpContext);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
_globalRouter.RouteRequest(webContext);
|
||||
@@ -46,7 +46,6 @@ public class GlobalRouterMiddleware
|
||||
}
|
||||
|
||||
private static bool IsIgnoreException(Exception ex) { return ex is ThreadAbortException; }
|
||||
|
||||
}
|
||||
|
||||
public static class GlobalRouterMiddlewareExtensions
|
||||
|
||||
@@ -5,15 +5,9 @@ namespace VAR.WebFormsCore.AspNetCore;
|
||||
|
||||
public static class DefaultMain
|
||||
{
|
||||
public static void WebFormCoreMain(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
public static void WebFormCoreMain(string[] args) { CreateHostBuilder(args).Build().Run(); }
|
||||
|
||||
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
|
||||
}
|
||||
@@ -11,14 +11,8 @@ public class Startup
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// If using Kestrel:
|
||||
services.Configure<KestrelServerOptions>(options =>
|
||||
{
|
||||
options.AddServerHeader = false;
|
||||
});
|
||||
services.Configure<KestrelServerOptions>(options => { options.AddServerHeader = false; });
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseGlobalRouterMiddleware(env);
|
||||
}
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseGlobalRouterMiddleware(env); }
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VAR.WebFormsCore\VAR.WebFormsCore.csproj" />
|
||||
<ProjectReference Include="..\VAR.WebFormsCore\VAR.WebFormsCore.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user