private Dictionary<string, MatchState> MatchForHeaders(Match match, NameValueCollection headers, IEnumerable<string> importantHeaders)
{
// Relates HTTP header names to match resutls.
var matches = new Dictionary<string, MatchState>();
// Iterates through the important header names.
var iterator = importantHeaders.GetEnumerator();
// Make the first match used the match passed
// into the method. Subsequent matches will
// use a new instance.
while(iterator.MoveNext())
{
matches.Add(iterator.Current, new MatchState(match) { TargetUserAgent = headers[iterator.Current] });
}
// Using each of the match instances pass the
// value to the match method and set the results.
// Done in parallel to improve performance if
// multi threading available.
Parallel.ForEach(matches, m =>
{
Match(headers[m.Key], m.Value);
});
return matches;
}