public static RequestInfo Collect(NancyContext context, IEnumerable<string> exclusions) {
            if (context == null)
                return null;

            var info = new RequestInfo {
                ClientIpAddress = context.Request.UserHostAddress,
                HttpMethod = context.Request.Method
            };

            if (!String.IsNullOrWhiteSpace(context.Request.Headers.UserAgent))
                info.UserAgent = context.Request.Headers.UserAgent;

            if (context.Request.Url != null) {
                info.Host = context.Request.Url.HostName;
                info.IsSecure = context.Request.Url.IsSecure;
                info.Path = context.Request.Url.BasePath + context.Request.Url.Path;
                info.Port = context.Request.Url.Port ?? 80;
            }

            if (!String.IsNullOrWhiteSpace(context.Request.Headers.Referrer))
                info.Referrer = context.Request.Headers.Referrer;

            var exclusionsArray = exclusions as string[] ?? exclusions.ToArray();
            info.Cookies = context.Request.Cookies.ToDictionary(exclusionsArray);

            if (context.Request.Url != null && !String.IsNullOrWhiteSpace(context.Request.Url.Query))
                info.QueryString = HttpUtility.ParseQueryString(context.Request.Url.Query).ToDictionary(exclusionsArray);

            return info;
        }
        public static RequestInfo Collect(HttpActionContext context, IEnumerable<string> exclusions) {
            if (context == null)
                return null;

            var info = new RequestInfo {
                ClientIpAddress = context.Request.GetClientIpAddress(),
                HttpMethod = context.Request.Method.Method
            };

            if (context.Request.Headers.UserAgent != null)
                info.UserAgent = context.Request.Headers.UserAgent.ToString();

            if (context.Request.RequestUri != null) {
                info.Host = context.Request.RequestUri.Host;
                info.IsSecure = context.Request.RequestUri.Scheme == "https";
                info.Path = String.IsNullOrEmpty(context.Request.RequestUri.LocalPath) ? "/" : context.Request.RequestUri.LocalPath;
                info.Port = context.Request.RequestUri.Port;
            }

            if (context.Request.Headers.Referrer != null)
                info.Referrer = context.Request.Headers.Referrer.ToString();

            var exclusionList = exclusions as string[] ?? exclusions.ToArray();
            info.Cookies = context.Request.Headers.GetCookies().ToDictionary(exclusionList);
            info.QueryString = context.Request.RequestUri.ParseQueryString().ToDictionary(exclusionList);
            
            // TODO Collect form data.
            return info;
        }
        public static RequestInfo Collect(HttpContextBase context, ExceptionlessConfiguration config) {
            if (context == null)
                return null;

            var info = new RequestInfo {
                HttpMethod = context.Request.HttpMethod,
                UserAgent = context.Request.UserAgent,
                Path = String.IsNullOrEmpty(context.Request.Path) ? "/" : context.Request.Path
            };

            try {
                info.ClientIpAddress = context.Request.UserHostAddress;
            } catch (ArgumentException ex) {
                config.Resolver.GetLog().Error(ex, "An error occurred while setting the Client Ip Address.");
            }

            try {
                info.IsSecure = context.Request.IsSecureConnection;
            } catch (ArgumentException ex) {
                config.Resolver.GetLog().Error(ex, "An error occurred while setting Is Secure Connection.");
            }

            if (context.Request.Url != null)
                info.Host = context.Request.Url.Host;

            if (context.Request.UrlReferrer != null)
                info.Referrer = context.Request.UrlReferrer.ToString();

            if (context.Request.Url != null)
                info.Port = context.Request.Url.Port;

            info.Cookies = context.Request.Cookies.ToDictionary(config.DataExclusions);

            if (context.Request.Form.Count > 0)
                info.PostData = context.Request.Form.ToDictionary(config.DataExclusions);
            else if (context.Request.ContentLength > 0 && context.Request.ContentLength < 1024 * 4) {
                try {
                    context.Request.InputStream.Position = 0;
                    using (var inputStream = new StreamReader(context.Request.InputStream))
                        info.PostData = inputStream.ReadToEnd();
                } catch (Exception ex) {
                    info.PostData = "Error retrieving POST data: " + ex.Message;
                }
            } else if (context.Request.ContentLength > 0) {
                string value = Math.Round(context.Request.ContentLength / 1024m, 0).ToString("N0");
                info.PostData = String.Format("Data is too large ({0}) to be included.", value + "kb");
            }

            try {
                info.QueryString = context.Request.QueryString.ToDictionary(config.DataExclusions);
            } catch (Exception ex) {
                config.Resolver.GetLog().Error(ex, "An error occurred while getting the cookies");
            }

            return info;
        }
        public static RequestInfo Collect(HttpActionContext context, IEnumerable<string> exclusions) {
            if (context == null)
                return null;

            var info = new RequestInfo {
                ClientIpAddress = context.Request.GetClientIpAddress(),
                HttpMethod = context.Request.Method.Method
            };

            if (context.Request.Headers.UserAgent != null)
                info.UserAgent = context.Request.Headers.UserAgent.ToString();

            if (context.Request.RequestUri != null) {
                info.Host = context.Request.RequestUri.Host;
                info.IsSecure = context.Request.RequestUri.Scheme == "https";
                info.Path = String.IsNullOrEmpty(context.Request.RequestUri.LocalPath) ? "/" : context.Request.RequestUri.LocalPath;
                info.Port = context.Request.RequestUri.Port;
            }

            if (context.Request.Headers.Referrer != null)
                info.Referrer = context.Request.Headers.Referrer.ToString();

            var exclusionList = exclusions as string[] ?? exclusions.ToArray();
            info.Cookies = context.Request.Headers.GetCookies().ToDictionary(exclusionList);

            //if (context.Request.Form.Count > 0) {
            //    info.PostData = context.Request.Form.AllKeys.Distinct().Where(k => !String.IsNullOrEmpty(k) && !_ignoredFormFields.Contains(k)).ToDictionary(k => k, k => {
            //        try {
            //            return context.Request.Form.Get(k);
            //        } catch (Exception ex) {
            //            return ex.Message;
            //        }
            //    });
            //} else if (context.Request.ContentLength > 0 && context.Request.ContentLength < 1024 * 4) {
            //    try {
            //        context.Request.InputStream.Position = 0;
            //        using (var inputStream = new StreamReader(context.Request.InputStream)) {
            //            info.PostData = inputStream.ReadToEnd();
            //        }
            //    } catch (Exception ex) {
            //        info.PostData = "Error retrieving POST data: " + ex.Message;
            //    }
            //} else if (context.Request.ContentLength > 0) {
            //    string value = Math.Round(context.Request.ContentLength / 1024m, 0).ToString("N0");
            //    info.PostData = String.Format("Data is too large ({0}) to be included.", value + "kb");
            //}

            info.QueryString = context.Request.RequestUri.ParseQueryString().ToDictionary(exclusionList);

            return info;
        }
        public static RequestInfo Collect(HttpContext context, IEnumerable<string> exclusions) {
            if (context == null)
                return null;
            
            var info = new RequestInfo {
                ClientIpAddress = context.GetClientIpAddress(),
                HttpMethod = context.Request.Method,
                IsSecure = context.Request.IsHttps,
                Path = context.Request.Path.HasValue ? context.Request.Path.Value : "/",
            };

            if (!String.IsNullOrEmpty(context.Request.Host.Host))
                info.Host = context.Request.Host.Host;

            if (context.Request.Host.Port.HasValue)
                info.Port = context.Request.Host.Port.Value;

            if (context.Request.Headers.ContainsKey(HeaderNames.UserAgent))
                info.UserAgent = context.Request.Headers[HeaderNames.UserAgent].ToString();

            if (context.Request.Headers.ContainsKey(HeaderNames.Referer))
                info.Referrer = context.Request.Headers[HeaderNames.Referer].ToString();

            var exclusionList = exclusions as string[] ?? exclusions.ToArray();
            info.Cookies = context.Request.Cookies.ToDictionary(exclusionList);
            info.QueryString = context.Request.Query.ToDictionary(exclusionList);

            if (context.Request.HasFormContentType && context.Request.Form.Count > 0) {
                info.PostData = context.Request.Form.ToDictionary(exclusionList);
            } else if (context.Request.ContentLength.HasValue && context.Request.ContentLength.Value > 0) {
                if (context.Request.ContentLength.Value < 1024 * 50) {
                    try {
                        if (context.Request.Body.Position > 0)
                            context.Request.Body.Position = 0;

                        using (var inputStream = new StreamReader(context.Request.Body))
                            info.PostData = inputStream.ReadToEnd();
                    } catch (Exception ex) {
                        info.PostData = "Error retrieving POST data: " + ex.Message;
                    }
                } else {
                    string value = Math.Round(context.Request.ContentLength.Value / 1024m, 0).ToString("N0");
                    info.PostData = String.Format("Data is too large ({0}kb) to be included.", value);
                }
            }

            return info;
        }
 protected bool Equals(RequestInfo other) {
     return string.Equals(UserAgent, other.UserAgent) && string.Equals(HttpMethod, other.HttpMethod) && IsSecure == other.IsSecure && string.Equals(Host, other.Host) && Port == other.Port && string.Equals(Path, other.Path) && string.Equals(Referrer, other.Referrer) && string.Equals(ClientIpAddress, other.ClientIpAddress) && Cookies.CollectionEquals(other.Cookies) && QueryString.CollectionEquals(other.QueryString) && Equals(Data, other.Data);
 }
 protected bool Equals(RequestInfo other)
 {
     return(string.Equals(UserAgent, other.UserAgent) && string.Equals(HttpMethod, other.HttpMethod) && IsSecure == other.IsSecure && string.Equals(Host, other.Host) && Port == other.Port && string.Equals(Path, other.Path) && string.Equals(Referrer, other.Referrer) && string.Equals(ClientIpAddress, other.ClientIpAddress) && Cookies.CollectionEquals(other.Cookies) && QueryString.CollectionEquals(other.QueryString) && Equals(Data, other.Data));
 }