diff --git a/Rest.Net/HttpListenerResponseExtensions.cs b/Rest.Net/HttpListenerResponseExtensions.cs
index 10de574..8d74f48 100644
--- a/Rest.Net/HttpListenerResponseExtensions.cs
+++ b/Rest.Net/HttpListenerResponseExtensions.cs
@@ -374,6 +374,34 @@ namespace MontoyaTech.Rest.Net
return response;
}
+ ///
+ /// Sets the response to include the given stream and sets the length and content type if possible.
+ ///
+ ///
+ ///
+ /// This response.
+ ///
+ public static HttpListenerResponse WithStream(this HttpListenerResponse response, Stream stream)
+ {
+ if (stream == null)
+ throw new ArgumentNullException($"{nameof(stream)} cannot be null.");
+
+ if (string.IsNullOrWhiteSpace(response.ContentType))
+ response.ContentType = "application/octet-stream";
+
+ try
+ {
+ response.ContentLength64 = stream.Length;
+ }
+ catch { }
+
+ stream.CopyTo(response.OutputStream);
+
+ response.OutputStream.Dispose();
+
+ return response;
+ }
+
///
/// Sets the status code for a given response.
///
diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj
index d4d765f..2d1b2c9 100644
--- a/Rest.Net/Rest.Net.csproj
+++ b/Rest.Net/Rest.Net.csproj
@@ -17,7 +17,7 @@
MontoyaTech.Rest.Net
MontoyaTech.Rest.Net
True
- 1.8.5
+ 1.8.6
Logo_Symbol_Black_Outline.png