public HTTPRequest(IEnumerable<string> requests)
{
Headers = new Dictionary<string, string>();
string host = "localhost";
string path = "/";
foreach (var req in requests) {
Match match = null;
if ((match = Regex.Match(req, @"^(\w+) +(\S+) +HTTP/1.\d$", RegexOptions.IgnoreCase)).Success) {
this.Method = match.Groups[1].Value.ToUpper();
path = match.Groups[2].Value;
}
else if ((match = Regex.Match(req, @"^Host:(.+)$", RegexOptions.IgnoreCase)).Success) {
host = match.Groups[1].Value.Trim();
Headers["HOST"] = host;
}
else if ((match = Regex.Match(req, @"^(\S*):(.+)$", RegexOptions.IgnoreCase)).Success) {
Headers[match.Groups[1].Value.ToUpper()] = match.Groups[2].Value.Trim();
}
}
Uri uri;
if (Uri.TryCreate("http://" + host + path, UriKind.Absolute, out uri)) {
this.Uri = uri;
}
else {
this.Uri = null;
}
}