예제 #1
0
 /// <summary>
 /// Sends a response with the given Content-Type and body. The Content-Length header will be set accordingly.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="data"></param>
 /// <param name="contentType"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static Task SendAsync([NotNull] this HttpResponse response, ArraySegment <byte> data, [NotNull] string contentType, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (string.IsNullOrEmpty(contentType))
     {
         throw new ArgumentException("Empty Content-Type is not allowed.");
     }
     response.ContentType = contentType;
     return(response.SendAsync(data, cancellationToken));
 }
예제 #2
0
 /// <summary>
 /// Sends a response with the given Content-Type, encoding, and body. The Content-Length header will be set accordingly.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="text"></param>
 /// <param name="encoding"></param>
 /// <param name="contentType"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static Task SendAsync([NotNull] this HttpResponse response, [NotNull] string text, [NotNull] Encoding encoding, [NotNull] string contentType, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (string.IsNullOrEmpty(contentType))
     {
         throw new ArgumentException("Empty Content-Type is not allowed.");
     }
     if (contentType.IndexOf("charset=", StringComparison.OrdinalIgnoreCase) < 0)
     {
         contentType += "; charset=" + encoding.WebName;
     }
     response.ContentType = contentType;
     return(response.SendAsync(text, encoding, cancellationToken));
 }
예제 #3
0
 /// <summary>
 /// Sends a response with the given Content-Type and body. The Content-Length header will be set accordingly.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="data"></param>
 /// <param name="contentType"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static Task SendAsync([NotNull] this HttpResponse response, [NotNull] byte[] data, [NotNull] string contentType, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(response.SendAsync(new ArraySegment <byte>(data), contentType, cancellationToken));
 }
예제 #4
0
 /// <summary>
 /// Sends a response with the given encoding and body. The Content-Length header will be set accordingly.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="text"></param>
 /// <param name="encoding"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static Task SendAsync([NotNull] this HttpResponse response, [NotNull] string text, [NotNull] Encoding encoding, CancellationToken cancellationToken = default(CancellationToken))
 {
     byte[] data = encoding.GetBytes(text);
     return(response.SendAsync(data, cancellationToken));
 }
예제 #5
0
 /// <summary>
 /// Sends a response with the given body. UTF-8 encoding will be used, and the Content-Length header will be set accordingly.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="text"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static Task SendAsync([NotNull] this HttpResponse response, [NotNull] string text, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(response.SendAsync(text, Encoding.UTF8, cancellationToken));
 }
예제 #6
0
 /// <summary>
 /// Sends a response with the given body. The Content-Length header will be set accordingly.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="data"></param>
 /// <param name="offset"></param>
 /// <param name="count"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static Task SendAsync([NotNull] this HttpResponse response, [NotNull] byte[] data, int offset, int count, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(response.SendAsync(new ArraySegment <byte>(data, offset, count), cancellationToken));
 }