Ejemplo n.º 1
0
        public async Task EnablesHttpsCompression_IfMatched()
        {
            var options      = new StaticFileOptions();
            var fileProvider = new TestFileProvider();

            fileProvider.AddFile("/foo.txt", new TestFileInfo
            {
                LastModified = new DateTimeOffset(2014, 1, 2, 3, 4, 5, TimeSpan.Zero)
            });
            var pathString              = new PathString("/test");
            var httpContext             = new DefaultHttpContext();
            var httpsCompressionFeature = new TestHttpsCompressionFeature();

            httpContext.Features.Set <IHttpsCompressionFeature>(httpsCompressionFeature);
            httpContext.Request.Path = new PathString("/test/foo.txt");
            var context = new StaticFileContext(httpContext, options, pathString, NullLogger.Instance, fileProvider, new FileExtensionContentTypeProvider());

            context.ValidatePath();
            var result = context.LookupFileInfo();

            Assert.True(result);

            await context.SendAsync();

            Assert.Equal(HttpsCompressionMode.Compress, httpsCompressionFeature.Mode);
        }
Ejemplo n.º 2
0
        public void SkipsHttpsCompression_IfNotMatched()
        {
            var options      = new StaticFileOptions();
            var fileProvider = new TestFileProvider();

            fileProvider.AddFile("/foo.txt", new TestFileInfo
            {
                LastModified = new DateTimeOffset(2014, 1, 2, 3, 4, 5, TimeSpan.Zero)
            });
            var pathString              = new PathString("/test");
            var httpContext             = new DefaultHttpContext();
            var httpsCompressionFeature = new TestHttpsCompressionFeature();

            httpContext.Features.Set <IHttpsCompressionFeature>(httpsCompressionFeature);
            httpContext.Request.Path = new PathString("/test/bar.txt");
            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, fileProvider, contentType, subPath);

            var result = context.LookupFileInfo();

            Assert.True(validateResult);
            Assert.True(contentTypeResult);
            Assert.False(result);

            Assert.Equal(HttpsCompressionMode.Default, httpsCompressionFeature.Mode);
        }