// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http { /// /// Convenience methods for writing to the response. /// public static class HttpResponseWritingExtensions { /// /// Writes the given text to the response body. UTF-8 encoding will be used. /// /// /// /// /// public static Task WriteAsync([NotNull] this HttpResponse response, [NotNull] string text, CancellationToken cancellationToken = default(CancellationToken)) { return response.WriteAsync(text, Encoding.UTF8, cancellationToken); } /// /// Writes the given text to the response body using the given encoding. /// /// /// /// /// /// public static Task WriteAsync([NotNull] this HttpResponse response, [NotNull] string text, [NotNull] Encoding encoding, CancellationToken cancellationToken = default(CancellationToken)) { byte[] data = encoding.GetBytes(text); return response.Body.WriteAsync(data, 0, data.Length, cancellationToken); } } }