Table of Contents

Class HttpResponseDecoratorExtensions

Namespace
Cuemon.AspNetCore.Http
Assembly
Cuemon.AspNetCore.dll

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

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.

public static void AddOrUpdateEntityTagHeader(this IDecorator<HttpResponse> decorator, HttpRequest request, ChecksumBuilder builder, bool isWeak = false)

Parameters

decorator IDecorator<HttpResponse>

The IDecorator<T> to extend.

request HttpRequest

An instance of the HttpRequest object.

builder ChecksumBuilder

A ChecksumBuilder that represents the integrity of the client.

isWeak bool

A value that indicates if this entity-tag header is a weak validator.

Exceptions

ArgumentNullException

decorator cannot be null -or- request cannot be null -or- builder cannot be null.

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.

public static void AddOrUpdateLastModifiedHeader(this IDecorator<HttpResponse> decorator, HttpRequest request, DateTime lastModified)

Parameters

decorator IDecorator<HttpResponse>

The IDecorator<T> to extend.

request HttpRequest

An instance of the HttpRequest object.

lastModified DateTime

A value that represents when the resource was either created or last modified.

Exceptions

ArgumentNullException

decorator cannot be null -or- request cannot be null.

See Also