diff --git a/Rest.Net/Rest.Net/Extensions/HttpListenerResponseExtensions.cs b/Rest.Net/Rest.Net/Extensions/HttpListenerResponseExtensions.cs index d18c596..694ff4b 100644 --- a/Rest.Net/Rest.Net/Extensions/HttpListenerResponseExtensions.cs +++ b/Rest.Net/Rest.Net/Extensions/HttpListenerResponseExtensions.cs @@ -93,10 +93,83 @@ namespace MontoyaTech.Rest.Net /// This response. public static HttpListenerResponse WithCookie(this HttpListenerResponse response, string name, string value) { - if (response.Cookies[name] == null) - response.Cookies.Add(new Cookie(name, value)); - else - response.Cookies[name].Value = value; + response.SetCookie(new Cookie(name, value)); + + return response; + } + + /// + /// Sets a cookie for a given response. + /// + /// + /// + /// + /// + /// This response. + public static HttpListenerResponse WithCookie(this HttpListenerResponse response, string name, string value, DateTime expires) + { + response.SetCookie(new Cookie(name, value) { Expires = expires }); + + return response; + } + + /// + /// Sets a cookie for a given response. + /// + /// + /// + /// + /// + /// This response. + public static HttpListenerResponse WithCookie(this HttpListenerResponse response, string name, string value, bool httpOnly) + { + response.SetCookie(new Cookie(name, value) { HttpOnly = httpOnly }); + + return response; + } + + /// + /// Sets a cookie for a given response. + /// + /// + /// + /// + /// + /// + /// This response. + public static HttpListenerResponse WithCookie(this HttpListenerResponse response, string name, string value, bool httpOnly, bool secure) + { + response.SetCookie(new Cookie(name, value) { HttpOnly = httpOnly, Secure = secure }); + + return response; + } + + /// + /// Sets a cookie for a given response. + /// + /// + /// + /// + /// + /// + /// + /// This response. + public static HttpListenerResponse WithCookie(this HttpListenerResponse response, string name, string value, bool httpOnly, bool secure, DateTime expires) + { + response.SetCookie(new Cookie(name, value) { HttpOnly = httpOnly, Secure = secure, Expires = expires }); + + return response; + } + + /// + /// Sets a cookie for a given response. + /// + /// + /// + /// This response. + public static HttpListenerResponse WithCookie(this HttpListenerResponse response, Cookie cookie) + { + response.SetCookie(cookie); return response; } diff --git a/Rest.Net/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net/Rest.Net.csproj index 84ab016..4ca6c3d 100644 --- a/Rest.Net/Rest.Net/Rest.Net.csproj +++ b/Rest.Net/Rest.Net/Rest.Net.csproj @@ -14,7 +14,7 @@ MontoyaTech.Rest.Net MontoyaTech.Rest.Net True - 1.0.2 + 1.0.3