src/packages/EmbedIO/HttpContextExtensions-Responses.cs
/// <summary>
/// Asynchronously sends a standard HTML response for the specified status code.
/// </summary>
/// <param name="this">The <see cref="IHttpContext"/> interface on which this method is called.</param>
/// <param name="statusCode">The HTTP status code of the response.</param>
/// <param name="writeAdditionalHtml">A callback function that may write additional HTML code
/// to a <see cref="TextWriter"/> representing the response output.
/// If not <see langword="null"/>, the callback is called immediately before closing the HTML <c>body</c> tag.</param>
/// <returns>A <see cref="Task"/> representing the ongoing operation.</returns>
/// <exception cref="NullReferenceException"><paramref name="this"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">There is no standard status description for <paramref name="statusCode"/>.</exception>
/// <seealso cref="SendStandardHtmlAsync(IHttpContext,int)"/>
Asynchronously sends a standard HTML response for the specified status code.
Asynchronously sends a standard HTML response for the specified status code .
public static Task SendStandardHtmlAsync(
            this IHttpContext @this,
            int statusCode,
            Action<TextWriter>? writeAdditionalHtml)
        {
            if (!HttpStatusDescription.TryGet(statusCode, out var statusDescription))
                throw new ArgumentException("Status code has no standard description.", nameof(statusCode));
            @this.Response.StatusCode = statusCode;
            @this.Response.StatusDescription = statusDescription;
            @this.Response.ContentType = MimeType.Html;
            @this.Response.ContentEncoding = Encoding.UTF8;
            using (var text = @this.OpenResponseText(Encoding.UTF8))
            {
                text.Write(StandardHtmlHeaderFormat, statusCode, statusDescription, Encoding.UTF8.WebName);
                writeAdditionalHtml?.Invoke(text);
                text.Write(StandardHtmlFooter);
            }
            return Task.CompletedTask;
        }
public static Task SendStandardHtmlAsync ( this IHttpContext @this , int statusCode , Action < TextWriter > ? writeAdditionalHtml ) { if ( ! HttpStatusDescription . TryGet ( statusCode , out var statusDescription ) ) throw new ArgumentException ( " " , nameof ( statusCode ) ) ; @this . Response . StatusCode = statusCode ; @this . Response . StatusDescription = statusDescription ; @this . Response . ContentType = MimeType . Html ; @this . Response . ContentEncoding = Encoding . UTF8 ; using ( var text = @this . OpenResponseText ( Encoding . UTF8 ) ) { text . Write ( StandardHtmlHeaderFormat , statusCode , statusDescription , Encoding . UTF8 . WebName ) ; writeAdditionalHtml ? . Invoke ( text ) ; text . Write ( StandardHtmlFooter ) ; } return Task . CompletedTask ; }
Asynchronously sends a standard HTML response for the specified status code.
Asynchronously sends a standard HTML response for the specified status code .
A  representing the ongoing operation.
A representing the ongoing operation .
None
There is no standard status description for .
There is no standard status description for .
IHttpContext
this
statusCode
int
The HTTP status code of the response.
The HTTP status code of the response .
writeAdditionalHtml
Action<TextWriter>?
A callback function that may write additional HTML code
to a  representing the response output.
If not , the callback is called immediately before closing the HTML body
A callback function that may write additional HTML code to a representing the response output . If not the callback is called immediately before closing the HTML body
this
The  interface on which this method is called.
The interface on which this method is called .
seealso
None