diff --git a/Leaf.xNet/~Http/CookieStorage.cs b/Leaf.xNet/~Http/CookieStorage.cs index 17471c6..d7e1dc7 100644 --- a/Leaf.xNet/~Http/CookieStorage.cs +++ b/Leaf.xNet/~Http/CookieStorage.cs @@ -2,6 +2,7 @@ using System.IO; using System.Net; using System.Runtime.Serialization.Formatters.Binary; +using System.Text; namespace Leaf.xNet { @@ -295,7 +296,27 @@ public void Remove(Uri uri, string name) /// Вернет строку содержащую все куки для адреса. public string GetCookieHeader(Uri uri) { - return Container.GetCookieHeader(uri); + string header = Container.GetCookieHeader(uri); + if (!UnescapeValuesOnSend) + return header; + + // Unescape cookies values + var sb = new StringBuilder(); + var cookies = header.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries); + + foreach (string cookie in cookies) + { + var kv = cookie.Split(new []{'='}, 2); + sb.Append(kv[0].Trim()); + sb.Append('='); + sb.Append(Uri.UnescapeDataString(kv[1].Trim())); + sb.Append("; "); + } + + if (sb.Length > 0) + sb.Remove(sb.Length - 2, 2); + + return sb.ToString(); } /// diff --git a/Leaf.xNet/~Http/HttpRequest.cs b/Leaf.xNet/~Http/HttpRequest.cs index 5529a00..84a4d4f 100644 --- a/Leaf.xNet/~Http/HttpRequest.cs +++ b/Leaf.xNet/~Http/HttpRequest.cs @@ -2172,12 +2172,8 @@ private string ToHeadersString(Dictionary headers) // Каждую Cookie в отдельный заголовок var cookies = header.Value.Split(new[] {"; "}, StringSplitOptions.None); - // ReSharper disable once ForCanBeConvertedToForeach - for (int i = 0; i < cookies.Length; i++) - { - string cookie = Cookies.UnescapeValuesOnSend ? Uri.UnescapeDataString(cookies[i]) : cookies[i]; + foreach (string cookie in cookies) headersBuilder.AppendFormat("Cookie: {0}\r\n", cookie); - } } headersBuilder.AppendLine();