-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
CollectionManagerExtensionsDll/Modules/DownloadManager/API/CookieContainerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Reflection; | ||
|
||
namespace CollectionManagerExtensionsDll.Modules.DownloadManager.API | ||
{ | ||
public static class CookieContainerExtensions | ||
{ | ||
/// <summary> | ||
/// Get List of <see cref="Cookie"/>s contained in <see cref="CookieContainer"/> using reflection | ||
/// </summary> | ||
/// <param name="container"></param> | ||
/// <returns></returns> | ||
public static List<Cookie> ToList(this CookieContainer container) | ||
{ | ||
var cookies = new List<Cookie>(); | ||
|
||
var table = (Hashtable)container.GetType().InvokeMember("m_domainTable", | ||
BindingFlags.NonPublic | | ||
BindingFlags.GetField | | ||
BindingFlags.Instance, | ||
null, | ||
container, | ||
new object[] { }); | ||
|
||
foreach (var key in table.Keys) | ||
{ | ||
|
||
Uri uri = null; | ||
|
||
var domain = key as string; | ||
|
||
if (domain == null) | ||
continue; | ||
|
||
if (domain.StartsWith(".")) | ||
domain = domain.Substring(1); | ||
|
||
var address = string.Format("http://{0}/", domain); | ||
|
||
if (Uri.TryCreate(address, UriKind.RelativeOrAbsolute, out uri) == false) | ||
continue; | ||
|
||
foreach (Cookie cookie in container.GetCookies(uri)) | ||
{ | ||
cookies.Add(cookie); | ||
} | ||
} | ||
|
||
return cookies; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters