public async Task RespectsIdentity() { var encoding = "gzip;q=0.5, deflate;q=0.3, br;q=0.2, identity"; var expectedPath = "/_framework/blazor.boot.json"; RequestDelegate next = (ctx) => Task.CompletedTask; var negotiator = new ContentEncodingNegotiator(next, CreateWebHostEnvironment()); var httpContext = new DefaultHttpContext(); httpContext.Request.Path = "/_framework/blazor.boot.json"; httpContext.Request.Headers.Append(HeaderNames.AcceptEncoding, encoding); await negotiator.InvokeAsync(httpContext); Assert.Equal(expectedPath, httpContext.Request.Path); Assert.False(httpContext.Response.Headers.TryGetValue(HeaderNames.ContentEncoding, out var selectedEncoding)); Assert.False(httpContext.Response.Headers.TryGetValue(HeaderNames.Vary, out var varyHeader)); }
public async Task AnyDoesNotPickEncodingIfNoFilesFound() { var encoding = "*"; var expectedPath = "/_framework/blazor.boot.json"; RequestDelegate next = (ctx) => Task.CompletedTask; var negotiator = new ContentEncodingNegotiator(next, CreateWebHostEnvironment(gzipExists: false, brotliExists: false)); var httpContext = new DefaultHttpContext(); httpContext.Request.Path = "/_framework/blazor.boot.json"; httpContext.Request.Headers.Append(HeaderNames.AcceptEncoding, encoding); await negotiator.InvokeAsync(httpContext); Assert.Equal(expectedPath, httpContext.Request.Path); Assert.False(httpContext.Response.Headers.TryGetValue(HeaderNames.ContentEncoding, out var selectedEncoding)); Assert.False(httpContext.Response.Headers.TryGetValue(HeaderNames.Vary, out var varyHeader)); }
public async Task UsesPreferredServerEncodingForEqualQualityValues() { var encoding = "gzip, deflate, br"; var expectedPath = "/_framework/blazor.boot.json.br"; var expectedEncoding = "br"; RequestDelegate next = (ctx) => Task.CompletedTask; var negotiator = new ContentEncodingNegotiator(next, CreateWebHostEnvironment()); var httpContext = new DefaultHttpContext(); httpContext.Request.Path = "/_framework/blazor.boot.json"; httpContext.Request.Headers.Append(HeaderNames.AcceptEncoding, encoding); await negotiator.InvokeAsync(httpContext); Assert.Equal(expectedPath, httpContext.Request.Path); Assert.True(httpContext.Response.Headers.TryGetValue(HeaderNames.ContentEncoding, out var selectedEncoding)); Assert.Equal(expectedEncoding, selectedEncoding); Assert.True(httpContext.Response.Headers.TryGetValue(HeaderNames.Vary, out var varyHeader)); Assert.Contains(HeaderNames.ContentEncoding, varyHeader.ToArray()); }
public async Task SkipsNonExistingFiles() { var encoding = "gzip;q=0.5, deflate;q=0.3, br"; var expectedPath = "/_framework/blazor.boot.json.gz"; var expectedEncoding = "gzip"; RequestDelegate next = (ctx) => Task.CompletedTask; var negotiator = new ContentEncodingNegotiator(next, CreateWebHostEnvironment(brotliExists: false)); var httpContext = new DefaultHttpContext(); httpContext.Request.Path = "/_framework/blazor.boot.json"; httpContext.Request.Headers.Append(HeaderNames.AcceptEncoding, encoding); await negotiator.InvokeAsync(httpContext); Assert.Equal(expectedPath, httpContext.Request.Path); Assert.True(httpContext.Response.Headers.TryGetValue(HeaderNames.ContentEncoding, out var selectedEncoding)); Assert.Equal(expectedEncoding, selectedEncoding); Assert.True(httpContext.Response.Headers.TryGetValue(HeaderNames.Vary, out var varyHeader)); Assert.Contains(HeaderNames.ContentEncoding, varyHeader.ToArray()); }