Table of Contents

HttpResponseDecoratorExtensions Class

Definition

Extension methods for the HttpResponse class hidden behind the IDecorator<T> interface.

public static class HttpResponseDecoratorExtensions
Inheritance
HttpResponseDecoratorExtensions

Examples

The following example demonstrates how to add ETag and Last-Modified HTTP response headers using the HttpResponseDecoratorExtensions class accessed through the Decorator class.

using System;
using System.Text;
using Cuemon;
using Cuemon.AspNetCore.Http;
using Cuemon.Data.Integrity;
using Cuemon.Security;
using Microsoft.AspNetCore.Http;

namespace MyApp.Examples;

public class HttpResponseDecoratorExtensionsExample
{
    public void AddCachingHeaders(HttpResponse response, HttpRequest request)
    {
        // Add an ETag header based on content integrity
        var builder = new ChecksumBuilder(() => new FowlerNollVo64());
        builder.CombineWith(Encoding.UTF8.GetBytes("content-data"));
        Decorator.Enclose(response).AddOrUpdateEntityTagHeader(request, builder);

        // Add a Last-Modified header
        var lastModified = new DateTime(2025, 6, 1, 12, 0, 0, DateTimeKind.Utc);
        Decorator.Enclose(response).AddOrUpdateLastModifiedHeader(request, lastModified);

}
}

Methods

Name Description
AddOrUpdateEntityTagHeader(IDecorator<HttpResponse>, HttpRequest, ChecksumBuilder, bool)

Attempts to add or update the enclosed HttpResponse of the decorator with the necessary HTTP response headers needed to provide entity tag header information.

AddOrUpdateLastModifiedHeader(IDecorator<HttpResponse>, HttpRequest, DateTime)

Attempts to add or update the enclosed HttpResponse of the decorator with the necessary HTTP response headers needed to provide last-modified information.

See Also