Cleaned up documentation. Response extension now sets the content length for a few extensions. Added WithNoBody response extension. Bumped package version to 1.3.7
This commit is contained in:
parent
c0f029ce08
commit
69e71bff0b
@ -16,6 +16,18 @@ namespace MontoyaTech.Rest.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class HttpListenerResponseExtensions
|
public static class HttpListenerResponseExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the response to have no body.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="response"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static HttpListenerResponse WithNoBody(this HttpListenerResponse response)
|
||||||
|
{
|
||||||
|
response.ContentLength64 = 0;
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the response content type to text and writes the given text to it.
|
/// Sets the response content type to text and writes the given text to it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -26,7 +38,10 @@ namespace MontoyaTech.Rest.Net
|
|||||||
{
|
{
|
||||||
response.ContentType = "text/plain; charset=utf-8";
|
response.ContentType = "text/plain; charset=utf-8";
|
||||||
|
|
||||||
|
response.ContentLength64 = text.Length;
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes(text);
|
var bytes = Encoding.UTF8.GetBytes(text);
|
||||||
|
|
||||||
response.OutputStream.Write(bytes, 0, bytes.Length);
|
response.OutputStream.Write(bytes, 0, bytes.Length);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
@ -63,6 +78,9 @@ namespace MontoyaTech.Rest.Net
|
|||||||
response.ContentType = "application/json; charset=utf-8";
|
response.ContentType = "application/json; charset=utf-8";
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj));
|
var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj));
|
||||||
|
|
||||||
|
response.ContentLength64 = bytes.Length;
|
||||||
|
|
||||||
response.OutputStream.Write(bytes, 0, bytes.Length);
|
response.OutputStream.Write(bytes, 0, bytes.Length);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
@ -133,6 +151,7 @@ namespace MontoyaTech.Rest.Net
|
|||||||
|
|
||||||
response.ContentType = mimeType;
|
response.ContentType = mimeType;
|
||||||
response.Headers.Add("Content-Deposition", $@"attachment; filename=""{Path.GetFileName(filePath)}""");
|
response.Headers.Add("Content-Deposition", $@"attachment; filename=""{Path.GetFileName(filePath)}""");
|
||||||
|
response.ContentLength64 = content.Length;
|
||||||
response.SendChunked = true;
|
response.SendChunked = true;
|
||||||
|
|
||||||
using (var responseStream = response.OutputStream)
|
using (var responseStream = response.OutputStream)
|
||||||
@ -218,6 +237,7 @@ namespace MontoyaTech.Rest.Net
|
|||||||
response.ContentType = mimeType;
|
response.ContentType = mimeType;
|
||||||
response.Headers.Add("Content-Deposition", $@"attachment; filename=""{Path.GetFileName(filePath)}""");
|
response.Headers.Add("Content-Deposition", $@"attachment; filename=""{Path.GetFileName(filePath)}""");
|
||||||
response.Headers.Add("Content-Encoding", "gzip");
|
response.Headers.Add("Content-Encoding", "gzip");
|
||||||
|
response.ContentLength64 = content.Length;
|
||||||
response.SendChunked = true;
|
response.SendChunked = true;
|
||||||
|
|
||||||
using (var responseStream = response.OutputStream)
|
using (var responseStream = response.OutputStream)
|
||||||
@ -237,6 +257,9 @@ namespace MontoyaTech.Rest.Net
|
|||||||
response.ContentType = "text/html; charset=utf-8";
|
response.ContentType = "text/html; charset=utf-8";
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes(html);
|
var bytes = Encoding.UTF8.GetBytes(html);
|
||||||
|
|
||||||
|
response.ContentLength64 = html.Length;
|
||||||
|
|
||||||
response.OutputStream.Write(bytes, 0, bytes.Length);
|
response.OutputStream.Write(bytes, 0, bytes.Length);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
<Version>1.3.6</Version>
|
<Version>1.3.7</Version>
|
||||||
<PackageReleaseNotes></PackageReleaseNotes>
|
<PackageReleaseNotes></PackageReleaseNotes>
|
||||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -28,7 +28,7 @@ namespace MontoyaTech.Rest.Net
|
|||||||
private Func<HttpListenerContext, HttpListenerResponse> Target;
|
private Func<HttpListenerContext, HttpListenerResponse> Target;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not to close the response after the route is invoked.
|
/// Whether or not to close the response after the route is invoked, default is true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CloseResponse = true;
|
public bool CloseResponse = true;
|
||||||
|
|
||||||
@ -38,9 +38,8 @@ namespace MontoyaTech.Rest.Net
|
|||||||
internal Route() { }
|
internal Route() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new route with a given method, syntax, target and optional close response flag.
|
/// Creates a new route with a given method, syntax, target and optional close response flag which defaults to true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name"></param>
|
|
||||||
/// <param name="method"></param>
|
/// <param name="method"></param>
|
||||||
/// <param name="syntax"></param>
|
/// <param name="syntax"></param>
|
||||||
/// <param name="target"></param>
|
/// <param name="target"></param>
|
||||||
@ -63,7 +62,6 @@ namespace MontoyaTech.Rest.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new route with a given method, syntax, target and optional close response flag.
|
/// Creates a new route with a given method, syntax, target and optional close response flag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name"></param>
|
|
||||||
/// <param name="method"></param>
|
/// <param name="method"></param>
|
||||||
/// <param name="syntax"></param>
|
/// <param name="syntax"></param>
|
||||||
/// <param name="target"></param>
|
/// <param name="target"></param>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user