#506 sync request cookies to Cookie header on demand
This commit is contained in:
parent
fb4d0555ef
commit
331b262c46
@ -59,6 +59,17 @@ namespace Flurl.Test.Http
|
|||||||
Assert.IsFalse(req.Cookies.ContainsKey("x"));
|
Assert.IsFalse(req.Cookies.ContainsKey("x"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void request_cookies_sync_with_cookie_header() {
|
||||||
|
var req = new FlurlRequest("http://cookies.com").WithCookie("x", "foo");
|
||||||
|
Assert.AreEqual("x=foo", req.Headers.TryGetValue("Cookie", out var val) ? val : null);
|
||||||
|
|
||||||
|
// should flow from CookieJar too
|
||||||
|
var jar = new CookieJar().AddOrUpdate("y", "bar", "http://cookies.com");
|
||||||
|
req = new FlurlRequest("http://cookies.com").WithCookies(jar);
|
||||||
|
Assert.AreEqual("y=bar", req.Headers.TryGetValue("Cookie", out val) ? val : null);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task can_send_cookies_per_request_initialized() {
|
public async Task can_send_cookies_per_request_initialized() {
|
||||||
HttpTest
|
HttpTest
|
||||||
|
@ -64,6 +64,7 @@ namespace Flurl.Http
|
|||||||
private FlurlHttpSettings _settings;
|
private FlurlHttpSettings _settings;
|
||||||
private IFlurlClient _client;
|
private IFlurlClient _client;
|
||||||
private Url _url;
|
private Url _url;
|
||||||
|
private IDictionary<string, object> _headers = new ConcurrentDictionary<string, object>();
|
||||||
private CookieJar _cookieJar;
|
private CookieJar _cookieJar;
|
||||||
private FlurlCall _redirectedFrom;
|
private FlurlCall _redirectedFrom;
|
||||||
|
|
||||||
@ -138,7 +139,13 @@ namespace Flurl.Http
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IDictionary<string, object> Headers { get; } = new ConcurrentDictionary<string, object>();
|
public IDictionary<string, object> Headers {
|
||||||
|
get {
|
||||||
|
if (Cookies.Any())
|
||||||
|
_headers["Cookie"] = CookieCutter.ToRequestHeader(Cookies);
|
||||||
|
return _headers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IDictionary<string, object> Cookies { get; } = new ConcurrentDictionary<string, object>();
|
public IDictionary<string, object> Cookies { get; } = new ConcurrentDictionary<string, object>();
|
||||||
@ -238,10 +245,6 @@ namespace Flurl.Http
|
|||||||
private void SyncHeadersAndCookies(HttpRequestMessage request) {
|
private void SyncHeadersAndCookies(HttpRequestMessage request) {
|
||||||
// copy any client-level (default) to FlurlRequest
|
// copy any client-level (default) to FlurlRequest
|
||||||
Headers.Merge(Client.Headers);
|
Headers.Merge(Client.Headers);
|
||||||
//Cookies.Merge(Client.Cookies);
|
|
||||||
|
|
||||||
if (Cookies.Any())
|
|
||||||
Headers["Cookie"] = CookieCutter.ToRequestHeader(Cookies);
|
|
||||||
|
|
||||||
// copy headers from FlurlRequest to HttpRequestMessage
|
// copy headers from FlurlRequest to HttpRequestMessage
|
||||||
foreach (var header in Headers)
|
foreach (var header in Headers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user