mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-04-24 22:37:06 -04:00
Revised deletion of cookies.
This commit is contained in:
parent
91c97ed232
commit
6d8eebcd30
2 changed files with 38 additions and 5 deletions
|
@ -338,6 +338,28 @@ namespace NzbDrone.Common.Test.Http
|
||||||
responseCookies.Resource.Cookies.Should().BeEmpty();
|
responseCookies.Resource.Cookies.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_clear_request_cookie()
|
||||||
|
{
|
||||||
|
var requestSet = new HttpRequest($"http://{_httpBinHost}/cookies");
|
||||||
|
requestSet.Cookies.Add("my", "cookie");
|
||||||
|
requestSet.AllowAutoRedirect = false;
|
||||||
|
requestSet.StoreRequestCookie = true;
|
||||||
|
requestSet.StoreResponseCookie = false;
|
||||||
|
|
||||||
|
var responseSet = Subject.Get<HttpCookieResource>(requestSet);
|
||||||
|
|
||||||
|
var requestClear = new HttpRequest($"http://{_httpBinHost}/cookies");
|
||||||
|
requestClear.Cookies.Add("my", null);
|
||||||
|
requestClear.AllowAutoRedirect = false;
|
||||||
|
requestClear.StoreRequestCookie = true;
|
||||||
|
requestClear.StoreResponseCookie = false;
|
||||||
|
|
||||||
|
var responseClear = Subject.Get<HttpCookieResource>(requestClear);
|
||||||
|
|
||||||
|
responseClear.Resource.Cookies.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_not_store_response_cookie()
|
public void should_not_store_response_cookie()
|
||||||
{
|
{
|
||||||
|
|
|
@ -153,12 +153,23 @@ namespace NzbDrone.Common.Http
|
||||||
{
|
{
|
||||||
foreach (var pair in request.Cookies)
|
foreach (var pair in request.Cookies)
|
||||||
{
|
{
|
||||||
var cookie = new Cookie(pair.Key, pair.Value, "/")
|
Cookie cookie;
|
||||||
|
if (pair.Value == null)
|
||||||
|
{
|
||||||
|
cookie = new Cookie(pair.Key, "", "/")
|
||||||
|
{
|
||||||
|
Expires = DateTime.Now.AddDays(-1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cookie = new Cookie(pair.Key, pair.Value, "/")
|
||||||
{
|
{
|
||||||
// Use Now rather than UtcNow to work around Mono cookie expiry bug.
|
// Use Now rather than UtcNow to work around Mono cookie expiry bug.
|
||||||
// See https://gist.github.com/ta264/7822b1424f72e5b4c961
|
// See https://gist.github.com/ta264/7822b1424f72e5b4c961
|
||||||
Expires = DateTime.Now.AddHours(1)
|
Expires = DateTime.Now.AddHours(1)
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
sourceContainer.Add((Uri)request.Url, cookie);
|
sourceContainer.Add((Uri)request.Url, cookie);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue