/// <summary> /// Specifies the body returned as part of the HTTP response. /// </summary> /// <param name="response">The <see cref="BasicHttpResponse" /> that returns in response to an HTTP request.</param> /// <param name="body">The value returned as body of the HTTP response.</param> /// <returns>The calling <see cref="BasicHttpResponse"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="response"/> is <c>null</c>.</exception> public static BasicHttpResponse WithBody(this BasicHttpResponse response, string body) { response = response ?? throw new ArgumentNullException(nameof(response)); response.ClearBody(); response.AppendToBody(body); return(response); }
/// <summary> /// Specifies the body returned as part of the HTTP response. /// </summary> /// <param name="response">The <see cref="BasicHttpResponse"/> that returns in response to an HTTP request.</param> /// <param name="path">The path to the file that contains the HTTP response.</param> /// <returns>The calling <see cref="BasicHttpResponse"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="response"/> is <c>null</c>.</exception> public static BasicHttpResponse WithFile(this BasicHttpResponse response, string path) { response = response ?? throw new ArgumentNullException(nameof(response)); var buffer = File.ReadAllBytes(path); response.ClearBody(); response.AppendToBody(buffer); var mimeType = MimeMapping.GetMimeMapping(path); response.Headers["Content-Type"] = mimeType; return(response); }
public void ClearBody_WhenCalled_RemovedAllBytes() { var newBytes = new byte[5] { 1, 2, 3, 4, 5 }; var response = new BasicHttpResponse(); response.AppendToBody(newBytes); response.ClearBody(); Assert.AreEqual(0, response.BodyLength); var bodyBytes = response.GetBody(); Assert.IsNotNull(bodyBytes); Assert.AreEqual(0, bodyBytes.Length); }