Don't persist cookies across requests by default

pull/20/head
ta264 4 years ago committed by Qstick
parent 29da0b7031
commit 95d5e0d347

@ -351,6 +351,7 @@ namespace NzbDrone.Common.Test.Http
var oldRequest = new HttpRequest($"https://{_httpBinHost2}/get");
oldRequest.Cookies["my"] = "cookie";
oldRequest.StoreRequestCookie = true;
var oldClient = new HttpClient(Array.Empty<IHttpRequestInterceptor>(), Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<Logger>());
@ -362,7 +363,7 @@ namespace NzbDrone.Common.Test.Http
}
[Test]
public void should_preserve_cookie_during_session()
public void should_preserve_cookie_during_session_when_asked()
{
GivenOldCookie();
@ -395,7 +396,7 @@ namespace NzbDrone.Common.Test.Http
var requestGet = new HttpRequest($"https://{_httpBinHost}/get");
requestGet.Cookies.Add("my", "cookie");
requestGet.AllowAutoRedirect = false;
requestGet.StoreRequestCookie = false;
requestGet.StoreRequestCookie.Should().BeFalse();
requestGet.StoreResponseCookie = false;
var responseGet = Subject.Get<HttpBinResource>(requestGet);
@ -409,12 +410,13 @@ namespace NzbDrone.Common.Test.Http
}
[Test]
public void should_store_request_cookie()
public void should_store_request_cookie_when_asked()
{
var requestGet = new HttpRequest($"https://{_httpBinHost}/get");
requestGet.Cookies.Add("my", "cookie");
requestGet.AllowAutoRedirect = false;
requestGet.StoreRequestCookie.Should().BeTrue();
requestGet.StoreRequestCookie.Should().BeFalse();
requestGet.StoreRequestCookie = true;
requestGet.StoreResponseCookie = false;
var responseGet = Subject.Get<HttpBinResource>(requestGet);

@ -14,8 +14,6 @@ namespace NzbDrone.Common.Http
Headers = new HttpHeader();
ConnectionKeepAlive = true;
AllowAutoRedirect = true;
StoreRequestCookie = true;
IgnorePersistentCookies = false;
Cookies = new Dictionary<string, string>();
if (!RuntimeInfo.IsProduction)
@ -40,7 +38,6 @@ namespace NzbDrone.Common.Http
public bool ConnectionKeepAlive { get; set; }
public bool LogResponseContent { get; set; }
public Dictionary<string, string> Cookies { get; private set; }
public bool IgnorePersistentCookies { get; set; }
public bool StoreRequestCookie { get; set; }
public bool StoreResponseCookie { get; set; }
public TimeSpan RequestTimeout { get; set; }

@ -26,6 +26,8 @@ namespace NzbDrone.Common.Http
public bool LogResponseContent { get; set; }
public NetworkCredential NetworkCredential { get; set; }
public Dictionary<string, string> Cookies { get; private set; }
public bool StoreRequestCookie { get; set; }
public bool StoreResponseCookie { get; set; }
public List<HttpFormData> FormData { get; private set; }
public Action<HttpRequest> PostProcess { get; set; }
@ -102,6 +104,8 @@ namespace NzbDrone.Common.Http
request.SuppressHttpError = SuppressHttpError;
request.UseSimplifiedUserAgent = UseSimplifiedUserAgent;
request.AllowAutoRedirect = AllowAutoRedirect;
request.StoreRequestCookie = StoreRequestCookie;
request.StoreResponseCookie = StoreResponseCookie;
request.ConnectionKeepAlive = ConnectionKeepAlive;
request.RateLimit = RateLimit;
request.LogResponseContent = LogResponseContent;
@ -357,6 +361,20 @@ namespace NzbDrone.Common.Http
return this;
}
public virtual HttpRequestBuilder StoreRequestCookies(bool val = true)
{
StoreRequestCookie = val;
return this;
}
public virtual HttpRequestBuilder StoreResponseCookies(bool val = true)
{
StoreResponseCookie = val;
return this;
}
public virtual HttpRequestBuilder AddFormParameter(string key, object value)
{
if (Method != HttpMethod.POST)

Loading…
Cancel
Save