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
decoratorIDecorator<HttpResponse>The IDecorator<T> to extend.
requestHttpRequestAn instance of the HttpRequest object.
builderChecksumBuilderA ChecksumBuilder that represents the integrity of the client.
isWeakboolA value that indicates if this entity-tag header is a weak validator.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-requestcannot be null -or-buildercannot 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
decoratorIDecorator<HttpResponse>The IDecorator<T> to extend.
requestHttpRequestAn instance of the HttpRequest object.
lastModifiedDateTimeA value that represents when the resource was either created or last modified.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-requestcannot be null.