diff --git a/Rest.Net/HttpListenerResponseExtensions.cs b/Rest.Net/HttpListenerResponseExtensions.cs
index dc2ff38..8e376ef 100644
--- a/Rest.Net/HttpListenerResponseExtensions.cs
+++ b/Rest.Net/HttpListenerResponseExtensions.cs
@@ -198,6 +198,34 @@ namespace MontoyaTech.Rest.Net
return response;
}
+ ///
+ /// Sets the response content type to a precompressed file and writes the file contents to the response.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static HttpListenerResponse WithPreCompressedFile(this HttpListenerResponse response, string filePath, byte[] content, string mimeType = null)
+ {
+ if (string.IsNullOrWhiteSpace(filePath))
+ throw new ArgumentException("filePath must not be null or empty");
+
+ if (string.IsNullOrWhiteSpace(mimeType))
+ mimeType = Path.GetExtension(filePath).GetMimeType();
+
+ response.ContentType = mimeType;
+ response.Headers.Add("Content-Deposition", $@"attachment; filename=""{Path.GetFileName(filePath)}""");
+ response.Headers.Add("Content-Encoding", "gzip");
+ response.SendChunked = true;
+
+ using (var responseStream = response.OutputStream)
+ responseStream.Write(content, 0, content.Length);
+
+ return response;
+ }
+
///
/// Sets the response content type to html and writes the given html to it.
///
diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj
index 50659b8..b72ca9f 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.3.4
+ 1.3.5
Logo_Symbol_Black_Outline.png