public HtmlEndpoint( RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, VersionInfoOptions options = null) { _options = options ?? new VersionInfoOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, _options); }
public UiMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, DashboardOptions options) { _options = options ?? new DashboardOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); _redirectUrlCheckRegex = new Regex($"^/?{Regex.Escape(_options.PathMatch)}/?$", RegexOptions.IgnoreCase); _homeUrlCheckRegex = new Regex($"^/?{Regex.Escape(_options.PathMatch)}/?index.html$", RegexOptions.IgnoreCase); }
public ReDocMiddleware( RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, ReDocOptions options) { _options = options ?? new ReDocOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); }
/// <summary> /// Initializes a new instance of the <see cref="SwaggerUIMiddleware" /> class. /// </summary> /// <param name="next">The next.</param> /// <param name="hostingEnv">The hosting env.</param> /// <param name="loggerFactory">The logger factory.</param> /// <param name="options">The options.</param> public SwaggerUIMiddleware( RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options) { _options = options ?? new SwaggerUIOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); }
/// <summary> /// Create a new <see cref="AltairMiddleware"/> /// </summary> /// <param name="nextMiddleware">The next middleware</param> /// <param name="hostingEnv">Provides information about the web hosting environment an application is running in</param> /// <param name="loggerFactory">Represents a type used to configure the logging system and create instances of <see cref="ILogger"/> from the registered <see cref="ILoggerProvider"/></param> /// <param name="options">Options to customize middleware</param> public AltairMiddleware(RequestDelegate nextMiddleware, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, GraphQLAltairOptions options) { if (nextMiddleware == null) { throw new ArgumentNullException(nameof(nextMiddleware)); } _options = options ?? throw new ArgumentNullException(nameof(options)); _staticFileMiddleware = CreateStaticFileMiddleware(nextMiddleware, hostingEnv, loggerFactory); }
public SwaggerApiDocmentExportMiddleware(RequestDelegate next, IWebHostEnvironment environment, ILoggerFactory loggerFactory) { StaticFileOptions options = new StaticFileOptions() { RequestPath = "/doc", FileProvider = new EmbeddedFileProvider(typeof(SwaggerApiDocmentExportMiddleware).Assembly, $"{typeof(SwaggerApiDocmentExportMiddleware).Assembly.ManifestModule.Name.Replace(".dll", ".node_modules")}") }; _staticFileMiddleware = new StaticFileMiddleware(next, environment, Options.Create(options), loggerFactory); }
public CachingProxy(RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, IOptions <CachingProxyConfig> config, ProxyHttpClient httpClient) { myLogger = loggerFactory.CreateLogger(GetType().FullName); myLogger.LogWarning("Initialising. Config:\n" + config.Value); myNext = next; myHttpClient = httpClient; myMinimumFreeDiskSpaceMb = config.Value.MinimumFreeDiskSpaceMb; myLocalCachePath = config.Value.LocalCachePath; if (myLocalCachePath == null) { throw new ArgumentNullException("", "LocalCachePath could not be null"); } if (!Directory.Exists(myLocalCachePath)) { throw new ArgumentException("LocalCachePath doesn't exist: " + myLocalCachePath); } myRemoteServers = new RemoteServers(config.Value.Prefixes.ToList(), config.Value.ContentTypeValidationPrefixes.ToList()); foreach (var remoteServer in myRemoteServers.Servers) { // force reconnection (and DNS re-resolve) every two minutes ServicePointManager.FindServicePoint(remoteServer.RemoteUri).ConnectionLeaseTimeout = 120000; } myContentTypeProvider = new FileExtensionContentTypeProvider(); myCacheFileProvider = new CacheFileProvider(myLocalCachePath); var staticFileOptions = new StaticFileOptions { FileProvider = myCacheFileProvider, ServeUnknownFileTypes = true, HttpsCompression = HttpsCompressionMode.DoNotCompress, ContentTypeProvider = myContentTypeProvider, OnPrepareResponse = ctx => { SetStatusHeader(ctx.Context, CachingProxyStatus.HIT); AddEternalCachingControl(ctx.Context); } }; myStaticFileMiddleware = new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory); myBlacklistRegex = !string.IsNullOrWhiteSpace(config.Value.BlacklistUrlRegex) ? new Regex(config.Value.BlacklistUrlRegex, RegexOptions.Compiled) : null; myRedirectToRemoteUrlsRegex = !string.IsNullOrWhiteSpace(config.Value.RedirectToRemoteUrlsRegex) ? new Regex(config.Value.RedirectToRemoteUrlsRegex, RegexOptions.Compiled) : null; }
/// <summary> /// Ctor /// </summary> /// <param name="next">A function that can process an HTTP request</param> /// <param name="hostingEnv">运行环境</param> /// <param name="loggerFactory">logger</param> public JcApiHelperUIMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory) { StaticFileOptions staticFileOptions = new StaticFileOptions { RequestPath = "/ApiHelper", FileProvider = new EmbeddedFileProvider(typeof(JcApiHelperUIMiddleware).GetTypeInfo().Assembly, embeddedFileNamespace), }; staticFileMiddleware = new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory); }
public BundlingMiddleware(RequestDelegate next, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor httpContextAccessor, IOptions<BundleGlobalOptions> globalOptions, IBundleManagerFactory bundleManagerFactory, BundleCollection bundles, IOptions<BundlingOptions> options) { if (next == null) throw new ArgumentNullException(nameof(next)); if (env == null) throw new ArgumentNullException(nameof(env)); if (loggerFactory == null) throw new ArgumentNullException(nameof(loggerFactory)); if (httpContextAccessor == null) throw new ArgumentNullException(nameof(httpContextAccessor)); if (globalOptions == null) throw new ArgumentNullException(nameof(globalOptions)); if (bundleManagerFactory == null) throw new ArgumentNullException(nameof(bundleManagerFactory)); if (bundles == null) throw new ArgumentNullException(nameof(bundles)); if (options == null) throw new ArgumentNullException(nameof(options)); _next = next; var optionsUnwrapped = options.Value; _bundleManager = optionsUnwrapped.BundleManager ?? bundleManagerFactory.Create(bundles, new BundlingContext { BundlesPathPrefix = optionsUnwrapped.RequestPath, StaticFilesPathPrefix = optionsUnwrapped.StaticFilesRequestPath }); optionsUnwrapped.FileProvider = optionsUnwrapped.FileProvider ?? new BundleFileProvider(_bundleManager, httpContextAccessor); var globalOptionsUnwrapped = globalOptions.Value; if (globalOptionsUnwrapped.EnableCacheHeader) { var originalPrepareResponse = optionsUnwrapped.OnPrepareResponse; optionsUnwrapped.OnPrepareResponse = ctx => { var headers = ctx.Context.Response.GetTypedHeaders(); headers.CacheControl = new CacheControlHeaderValue { MaxAge = globalOptionsUnwrapped.CacheHeaderMaxAge }; originalPrepareResponse?.Invoke(ctx); }; } _staticFileMiddleware = new StaticFileMiddleware(next, env, options, loggerFactory); }
/// <summary> /// Constructs a new instance of <see cref="AdminUIMiddleware"/>. /// </summary> /// <param name="options">Options for configuring <see cref="AdminUIMiddleware"/> middleware.</param> /// <param name="loggerFactory">Represents a type used to configure the logging system.</param> /// <param name="hostingEnvironment">Provides information about the web hosting environment an application is running in.</param> /// <param name="next">A function that can process an HTTP request.</param> public AdminUIMiddleware( AdminUIOptions options, ILoggerFactory loggerFactory, IWebHostEnvironment hostingEnvironment, RequestDelegate next ) { _options = options ?? new AdminUIOptions(); _next = next; _staticFileMiddleware = CreateStaticFileMiddleware(hostingEnvironment, loggerFactory, options); _logger = loggerFactory.CreateLogger <AdminUIMiddleware>(); }
public CompressedStaticFilesMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, IOptions <StaticFileOptions> staticFileOptions, ILoggerFactory loggerFactory) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (hostingEnv == null) { throw new ArgumentNullException(nameof(hostingEnv)); } if (staticFileOptions == null) { throw new ArgumentNullException(nameof(staticFileOptions)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _hostingEnv = hostingEnv; _logger = loggerFactory.CreateLogger <CompressedStaticFilesMiddleware>(); var contentTypeProvider = staticFileOptions.Value.ContentTypeProvider ?? new FileExtensionContentTypeProvider(); var fileExtensionContentTypeProvider = contentTypeProvider as FileExtensionContentTypeProvider; if (fileExtensionContentTypeProvider != null) { fileExtensionContentTypeProvider.Mappings[".br"] = "application/brotli"; } staticFileOptions.Value.ContentTypeProvider = contentTypeProvider; staticFileOptions.Value.FileProvider = staticFileOptions.Value.FileProvider ?? hostingEnv.WebRootFileProvider; staticFileOptions.Value.OnPrepareResponse = ctx => { foreach (var compressionType in compressionTypes.Keys) { var fileExtension = compressionTypes[compressionType]; if (ctx.File.Name.EndsWith(fileExtension, StringComparison.OrdinalIgnoreCase)) { string contentType = null; if (contentTypeProvider.TryGetContentType(ctx.File.PhysicalPath.Remove(ctx.File.PhysicalPath.Length - fileExtension.Length, fileExtension.Length), out contentType)) { ctx.Context.Response.ContentType = contentType; } ctx.Context.Response.Headers.Add("Content-Encoding", new[] { compressionType }); } } }; _base = new StaticFileMiddleware(next, hostingEnv, staticFileOptions, loggerFactory); }
public HttpReportsDashboardUIMiddleware(RequestDelegate next, IOptions <DashboardUIOptions> options, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory) { _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory); _serializerSettings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), }; }
/// <summary> /// Ctor /// </summary> /// <param name="next">A function that can process an HTTP request</param> /// <param name="hostingEnv">运行环境</param> /// <param name="loggerFactory">logger</param> public JcApiHelperUIMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory) { apiHelperAssembly = typeof(JcApiHelperUIMiddleware).GetTypeInfo().Assembly; apiResources = apiHelperAssembly.GetManifestResourceNames().ToList(); StaticFileOptions staticFileOptions = new StaticFileOptions { RequestPath = "/ApiHelper", FileProvider = new EmbeddedFileProvider(apiHelperAssembly, embeddedFileNamespace) }; staticFileMiddleware = new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory); }
public void Should_return_correct_mimetype() { var middleware = new StaticFileMiddleware(new DummyNext()); var context = new OwinContext { Request = { Path = new PathString("/js/app.constants.js"), Method = "GET" } }; middleware.Invoke(context); Assert.AreEqual(("application/javascript"), context.Response.ContentType); }
public RapiDocMiddleware( RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, RapiDocOptions options) { _options = options ?? new RapiDocOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); _jsonSerializerOptions = new JsonSerializerOptions() { AllowTrailingCommas = true, }; }
public ReDocMiddleware( RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, ReDocOptions options) { _options = options ?? new ReDocOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); _jsonSerializerOptions = new JsonSerializerOptions(); _jsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; _jsonSerializerOptions.IgnoreNullValues = true; _jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, false)); }
public ChoreographyMiddleware( RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, ChoreographyOptions options, IChoreographyDescriptor choreographyDescriptor) { _options = options ?? new ChoreographyOptions(); _choreographyDescriptor = choreographyDescriptor; _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); _jsonSerializerOptions = new JsonSerializerOptions(); _jsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; _jsonSerializerOptions.IgnoreNullValues = false; _jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, false)); }
public void Should_only_handle_get_and_head() { var middleware = new StaticFileMiddleware(new DummyNext()); var context = new OwinContext { Request = { Path = new PathString("/whatever"), Method = "POST" } }; middleware.Invoke(context); Assert.AreEqual(null, context.Response.ContentLength); Assert.AreEqual(null, context.Response.ContentType); }
public DeepLinkingMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, DeepLinkingMiddlewareOptions options) { this.next = next; this.options = options; var staticFileOptions = new StaticFileOptions() { FileProvider = new PhysicalFileProvider(options.AbsolutePhysicalRootPath), }; staticFileMiddleware = new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory); }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var staticFileOptions = new StaticFileOptions { RequestPath = "/resources", FileProvider = new EmbeddedFileProvider(Assembly, EmbeddedFileNamespace), }; var staticMiddleware = new StaticFileMiddleware( next, webHostEnvironment, Options.Create(staticFileOptions), loggerFactory); await staticMiddleware.Invoke(context); }
public void Should_handle_get_and_head(string method) { var middleware = new StaticFileMiddleware(new DummyNext()); var context = new OwinContext { Request = { Path = new PathString("/js/app.js"), Method = method } }; middleware.Invoke(context); Assert.IsNotNull(context.Response.ContentLength); Assert.IsNotEmpty(context.Response.ContentType); }
public MP2WebMiddleware(OwinMiddleware next) : base(next) { var staticFileOptions = new StaticFileOptions { FileSystem = new SpaFileSystem(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"ClientApp"), "index.html"), RequestPath = new PathString("/MP2Web"), ServeUnknownFileTypes = true, }; _staticFileMiddleware = new StaticFileMiddleware(e => next.Invoke(new OwinContext(e)), staticFileOptions); _defaultFilesMiddleware = new DefaultFilesMiddleware(_staticFileMiddleware.Invoke, new DefaultFilesOptions { FileSystem = staticFileOptions.FileSystem, RequestPath = staticFileOptions.RequestPath }); }
public void Should_find_file_embedded_in_assembly() { var middleware = new StaticFileMiddleware(new DummyNext()); var context = new OwinContext { Request = { Path = new PathString("/NoIE.html"), Method = "GET" } }; middleware.Invoke(context); const long sizeOfEmbeddedHtmlFile = 1302; // this is the NoIe.html file embedded into ServicePulse.Host.exe Assert.AreEqual(sizeOfEmbeddedHtmlFile, context.Response.ContentLength); Assert.AreEqual(("text/html"), context.Response.ContentType); }
public SerilogUiMiddleware( RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, UiOptions options, ILogger <SerilogUiMiddleware> logger ) { _options = options; _logger = logger; _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory); _jsonSerializerOptions = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver(), Formatting = Formatting.None }; }
public void LookupFileInfo_ReturnsFalse_IfFileDoesNotExist() { // Arrange var options = new StaticFileOptions(); var httpContext = new DefaultHttpContext(); var pathString = PathString.Empty; var validateResult = StaticFileMiddleware.ValidatePath(httpContext, pathString, out var subPath); var contentTypeResult = StaticFileMiddleware.LookupContentType(new FileExtensionContentTypeProvider(), options, subPath, out var contentType); var context = new StaticFileContext(httpContext, options, NullLogger.Instance, new TestFileProvider(), contentType, subPath); // Act var lookupResult = context.LookupFileInfo(); // Assert Assert.True(validateResult); Assert.False(contentTypeResult); Assert.False(lookupResult); }
public void Should_find_deep_linking_file_embedded_in_assembly() { var middleware = new StaticFileMiddleware(new DummyNext()); var context = new OwinContext { Request = { Path = new PathString("/js/views/message/editor/messageEditorModal.controller.js"), Method = "GET" } }; middleware.Invoke(context); const long sizeOfEmbeddedHtmlFile = 8551; // this is the messageEditorModal.controller.js file embedded into ServicePulse.Host.exe Assert.AreEqual(sizeOfEmbeddedHtmlFile, context.Response.ContentLength); Assert.AreEqual(("application/javascript"), context.Response.ContentType); }
public void Should_find_prefer_constants_file_on_disk_over_embedded_if_both_exist() { var middleware = new StaticFileMiddleware(new DummyNext()); var context = new OwinContext { Request = { Path = new PathString("/js/app.constants.js"), //this exists both BOTH embedded in ServicePulse.Host.exe and on disk Method = "GET" } }; middleware.Invoke(context); const long sizeOfFileOnDisk = 231; // this is the /app/js/app.constants.js file Assert.AreEqual(sizeOfFileOnDisk, context.Response.ContentLength); Assert.AreEqual(("application/javascript"), context.Response.ContentType); }
public async Task Should_return_correct_mimetype() { var middleware = new StaticFileMiddleware(new DummyNext()); var context = new OwinContext { Request = { Path = new PathString("/js/app.constants.js"), Method = "GET" }, Response = { Body = new MemoryStream() } }; await middleware.Invoke(context); Assert.AreEqual("application/javascript", context.Response.ContentType); }
public SwaggerUIMiddleware( RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options) { _options = options ?? new SwaggerUIOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); _jsonSerializerOptions = new JsonSerializerOptions(); #if NET6_0 _jsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; #else _jsonSerializerOptions.IgnoreNullValues = true; #endif _jsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; _jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, false)); }
public Html5ModeMiddleware(AppFunc next, Html5ModeOptions options) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } m_Options = options; m_InnerMiddleware = new StaticFileMiddleware(next, options.FileServerOptions.StaticFileOptions); m_EntryPointAwareInnerMiddleware = new StaticFileMiddleware((environment) => { var context = new OwinContext(environment); context.Request.Path = m_Options.EntryPath; return(m_InnerMiddleware.Invoke(environment)); }, options.FileServerOptions.StaticFileOptions); }