コード例 #1
0
    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));
    }
コード例 #2
0
    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));
    }
コード例 #3
0
    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());
    }
コード例 #4
0
    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());
    }