Table of Contents

Class EntityTagCacheableValidator

Namespace
Cuemon.Extensions.AspNetCore.Http.Headers
Assembly
Cuemon.Extensions.AspNetCore.dll

An HTTP validator that conforms to the ETag response header.

public class EntityTagCacheableValidator : ICacheableValidator
Inheritance
EntityTagCacheableValidator
Implements
Extension Methods

Examples

The following example demonstrates how to register as a cacheable validator in the ASP.NET Core pipeline.

using System;
using Cuemon.AspNetCore.Http.Headers;
using Cuemon.Extensions.AspNetCore.Http.Headers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace DocfxExamples;

public class EntityTagCacheableValidatorExample
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CacheableOptions>(options =>
        {
            options.Validators.Add(new EntityTagCacheableValidator());
        });

        var serviceProvider = services.BuildServiceProvider();
        var options = serviceProvider.GetRequiredService<IOptions<CacheableOptions>>();
        Console.WriteLine(options.Value.Validators.Count); // 1
        Console.WriteLine(options.Value.Validators[0] is EntityTagCacheableValidator); // True

}
}

Methods

ProcessAsync(HttpContext, Stream)

Called asynchronously before the bodyStream is conditionally written to the response.

public Task ProcessAsync(HttpContext context, Stream bodyStream)

Parameters

context HttpContext

The HttpContext of the current request.

bodyStream Stream

The intercepted Stream of the response body.

Returns

Task

A Task that represents the execution of this validator.

See Also