diff --git a/.gitignore b/.gitignore index f1e3d20..34e528e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# Ignore stuff like nuget.exe +*.exe + # Build results [Dd]ebug/ [Dd]ebugPublic/ diff --git a/DistillNET/DistillNET/DistillNET.nuspec b/DistillNET/DistillNET/DistillNET.nuspec new file mode 100644 index 0000000..ef27ea0 --- /dev/null +++ b/DistillNET/DistillNET/DistillNET.nuspec @@ -0,0 +1,26 @@ + + + + DistillNET + 1.0.1 + DistillNET + TechnikEmpire + TechnikEmpire + https://www.mozilla.org/en-US/MPL/2.0/ + false + DistillNET is a library for matching and filtering HTTP requests and HTML response content using the Adblock Plus Filter format. + Matching function(s) now use NameValueCollection. + Copyright 2017 Jesse Nicholson + DistillNET Adblock AdblockPlus Adblock-Plus URL-Filter URL-Filtering Content-Filter Filter + + + + + + + + + + + + \ No newline at end of file diff --git a/DistillNET/DistillNET/DistillNET/UrlFilter.cs b/DistillNET/DistillNET/DistillNET/UrlFilter.cs index f62096d..4e5f1ea 100644 --- a/DistillNET/DistillNET/DistillNET/UrlFilter.cs +++ b/DistillNET/DistillNET/DistillNET/UrlFilter.cs @@ -8,6 +8,7 @@ using DistillNET.Extensions; using System; using System.Collections.Generic; +using System.Collections.Specialized; namespace DistillNET { @@ -563,14 +564,14 @@ internal UrlFilter(string originalRule, List parts, Ur /// /// True if this filter is a positive match against the supplied URI, false otherwise. /// - public bool IsMatch(Uri uri, Dictionary rawHeaders) + public bool IsMatch(Uri uri, NameValueCollection rawHeaders) { // Make sure that the headers match up with our options. if(this.Options != UrlFilterOptions.None) { - string headerVal = string.Empty; + string headerVal = null; long xmlHttpRequestBits = ((OptionsLong & (long)UrlFilterOptions.ExceptXmlHttpRequest) | (OptionsLong & (long)UrlFilterOptions.XmlHttpRequest)); - if(rawHeaders.TryGetValue("X-Requested-With", out headerVal)) + if((headerVal = rawHeaders.Get("X-Requested-With")) != null) { if(headerVal.Equals("XMLHttpRequest", StringComparison.OrdinalIgnoreCase)) { @@ -589,7 +590,7 @@ public bool IsMatch(Uri uri, Dictionary rawHeaders) } long thirdPartyBits = ((OptionsLong & (long)UrlFilterOptions.ThirdParty) | (OptionsLong & (long)UrlFilterOptions.ExceptThirdParty)); - if(rawHeaders.TryGetValue("Referer", out headerVal)) + if((headerVal = rawHeaders.Get("Referer")) != null) { if(headerVal.Equals(uri.Host, StringComparison.OrdinalIgnoreCase)) { @@ -617,7 +618,7 @@ public bool IsMatch(Uri uri, Dictionary rawHeaders) long contentTypeBits = ((OptionsLong & (long)UrlFilterOptions.Image) | (OptionsLong & (long)UrlFilterOptions.Script) | (OptionsLong & (long)UrlFilterOptions.StyleSheet) | (OptionsLong & (long)UrlFilterOptions.ExceptImage) | (OptionsLong & (long)UrlFilterOptions.ExceptScript) | (OptionsLong & (long)UrlFilterOptions.ExceptStyleSheet)); - if(rawHeaders.TryGetValue("Content-Type", out headerVal)) + if((headerVal = rawHeaders.Get("Content-Type")) != null) { if(headerVal.IndexOfQuick("script") != -1) { diff --git a/DistillNET/DistillNET/Properties/AssemblyInfo.cs b/DistillNET/DistillNET/Properties/AssemblyInfo.cs index 5c79a25..fb0116c 100644 --- a/DistillNET/DistillNET/Properties/AssemblyInfo.cs +++ b/DistillNET/DistillNET/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] diff --git a/DistillNET/Tests/Program.cs b/DistillNET/Tests/Program.cs index 5f37ab6..ca8ba0f 100644 --- a/DistillNET/Tests/Program.cs +++ b/DistillNET/Tests/Program.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Diagnostics; using System.IO; @@ -15,7 +16,7 @@ namespace DistillNET internal class Program { private static void Main(string[] args) - { + { var parser = new AbpFormatRuleParser(); string easylistPath = AppDomain.CurrentDomain.BaseDirectory + "easylist.txt"; @@ -108,7 +109,7 @@ private static void TestFilterMatching() // "in-the-wild" kind of stuff. var rp = new AbpFormatRuleParser(); var filter = rp.ParseAbpFormattedRule("||silly.com^stoopid^url^*1$xmlhttprequest,script,~third-party", 1) as UrlFilter; - var headers = new Dictionary(StringComparer.OrdinalIgnoreCase) + var headers = new NameValueCollection(StringComparer.OrdinalIgnoreCase) { { "X-Requested-With", "XmlHttpRequest" }, { "Content-Type", "script" }, @@ -118,8 +119,7 @@ private static void TestFilterMatching() double d = 10000000; var results = new List((int)d); - var sw2 = new Stopwatch(); - + var sw2 = new Stopwatch(); Console.WriteLine("Roughly Benchmarking Filter Matching Speed"); sw2.Start(); for(int i = 0; i < d; ++i)