/// <summary> /// Specifies the <paramref name="statusCode"/>, <paramref name="content"/>, <paramref name="encoding"/> and <paramref name="mediaType"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> /// <param name="encoding">The encoding.</param> /// <param name="mediaType">The media type.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, string content, Encoding encoding, string mediaType) where TResult : IResponseResult { return(responds.Respond(statusCode, content, new MediaTypeHeaderValue(mediaType ?? "text/plain") { CharSet = (encoding ?? Encoding.UTF8).WebName })); }
/// <summary> /// Specifies a function that returns the response for a request. /// </summary> /// <param name="responds"></param> /// <param name="response">The function that provides the response message to return for given request.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, Func <HttpRequestMessage, HttpResponseMessage> response) where TResult : IResponseResult { if (responds is null) { throw new ArgumentNullException(nameof(responds)); } if (response is null) { throw new ArgumentNullException(nameof(response)); } return(responds.Respond((request, _) => Task.FromResult(response(request)))); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, HttpContent content) where TResult : IResponseResult { if (responds is null) { throw new ArgumentNullException(nameof(responds)); } if (content is null) { throw new ArgumentNullException(nameof(content)); } return(responds.Respond(async() => new HttpResponseMessage(statusCode) { Content = await content.CloneAsByteArrayContentAsync().ConfigureAwait(false) })); }
/// <summary> /// Specifies the <paramref name="statusCode"/>, <paramref name="content"/> and <paramref name="mediaType"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> /// <param name="mediaType">The media type.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, string content, MediaTypeHeaderValue mediaType) where TResult : IResponseResult { if (content is null) { throw new ArgumentNullException(nameof(content)); } return(responds.Respond(() => new HttpResponseMessage(statusCode) { Content = new StringContent(content) { Headers = { ContentType = mediaType } } })); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="streamContent"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="streamContent">The response stream.</param> /// <param name="mediaType">The media type.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, Stream streamContent, MediaTypeHeaderValue mediaType) where TResult : IResponseResult { if (streamContent is null) { throw new ArgumentNullException(nameof(streamContent)); } if (!streamContent.CanRead) { throw new ArgumentException("Cannot read from stream.", nameof(streamContent)); } byte[] buffer; using (var ms = new MemoryStream()) { streamContent.CopyTo(ms); buffer = ms.ToArray(); } return(responds.Respond(statusCode, () => new MemoryStream(buffer), mediaType)); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="content">The response content.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, string content) where TResult : IResponseResult { return(responds.Respond(HttpStatusCode.OK, content)); }
/// <summary> /// Specifies the <paramref name="statusCode"/> response for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode) where TResult : IResponseResult { return(responds.Respond(() => new HttpResponseMessage(statusCode))); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="content">The response content.</param> public static T Respond <T>(this IResponds <T> responds, HttpContent content) where T : IResponseResult { return(responds.Respond(HttpStatusCode.OK, content)); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="streamContent"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="streamContent">The response stream.</param> /// <param name="mediaType">The media type.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, Stream streamContent, MediaTypeHeaderValue mediaType) where TResult : IResponseResult { return(responds.Respond(HttpStatusCode.OK, streamContent, mediaType)); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="streamContent"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="streamContent">The response stream.</param> /// <param name="mediaType">The media type.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, Stream streamContent, string mediaType) where TResult : IResponseResult { return(responds.Respond(statusCode, streamContent, mediaType is null ? null : MediaTypeHeaderValue.Parse(mediaType))); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="streamContent"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="streamContent">The response stream.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, Stream streamContent) where TResult : IResponseResult { return(responds.Respond(statusCode, streamContent, (MediaTypeHeaderValue)null)); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/>, <paramref name="content"/>, <paramref name="encoding"/> and <paramref name="mediaType"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="content">The response content.</param> /// <param name="encoding">The encoding.</param> /// <param name="mediaType">The media type.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, string content, Encoding encoding, string mediaType) where TResult : IResponseResult { return(responds.Respond(HttpStatusCode.OK, content, encoding, mediaType)); }
/// <summary> /// Specifies the <paramref name="statusCode"/>, <paramref name="content"/> and <paramref name="mediaType"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> /// <param name="mediaType">The media type.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, string content, string mediaType) where TResult : IResponseResult { return(responds.Respond(statusCode, content, null, mediaType)); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, string content) where TResult : IResponseResult { return(responds.Respond(statusCode, content, (string)null)); }