using System; using EmbedIO.Utilities; namespace EmbedIO { /// /// Provides extension methods for types implementing . /// public static class HttpResponseExtensions { /// /// Sets the necessary headers to disable caching of a response on the client side. /// /// The interface on which this method is called. /// is . public static void DisableCaching(this IHttpResponse @this) { var headers = @this.Headers; headers.Set(HttpHeaderNames.Expires, "Sat, 26 Jul 1997 05:00:00 GMT"); headers.Set(HttpHeaderNames.LastModified, HttpDate.Format(DateTime.UtcNow)); headers.Set(HttpHeaderNames.CacheControl, "no-store, no-cache, must-revalidate"); headers.Add(HttpHeaderNames.Pragma, "no-cache"); } /// /// Prepares a standard response without a body for the specified status code. /// /// The interface on which this method is called. /// The HTTP status code of the response. /// is . /// There is no standard status description for . public static void SetEmptyResponse(this IHttpResponse @this, int statusCode) { if (!HttpStatusDescription.TryGet(statusCode, out var statusDescription)) throw new ArgumentException("Status code has no standard description.", nameof(statusCode)); @this.StatusCode = statusCode; @this.StatusDescription = statusDescription; @this.ContentType = MimeType.Default; @this.ContentEncoding = null; } } }