Exemplo n.º 1
0
        public static RaygunRequestMessage Build(OwinEnvironment environment)
        {
            var request = new OwinRequest(environment);

            // ToDo: limit querystring, form, and header values to 256 characters
            var message = new RaygunRequestMessage();

            message.HostName   = request.Host.Value;
            message.Url        = request.Uri.AbsolutePath;
            message.HttpMethod = request.Method;
            message.IPAddress  = request.RemoteIpAddress; // ToDo: bring this up to par with the official client

            // ToDo: filter querystring values
            message.QueryString = request.Query.ToDictionary(_ => _.Key, _ => string.Join(", ", _.Value));

            // ToDo: filter form values (add 'password' by default?)
            message.Form = request.ReadForm().ToDictionary(_ => _.Key, _ => string.Join(", ", _.Value));

            // ToDo: filter headers
            message.Headers = request.Headers.ToDictionary(_ => _.Key, _ => string.Join(", ", _.Value));
            message.Headers.Remove("Cookie");

            message.Cookies = GetCookies(request.Cookies);

            if (request.ContentType != "text/html" && request.ContentType != "application/x-www-form-urlencoded" && request.Method != "GET")
            {
                var text = request.BodyAsString();

                message.RawData = text.Substring(0, Math.Min(4096, text.Length));
            }

            message.Data = GetData(request).Where(_ => _.Value != null).ToDictionary(_ => _.Key, _ => _.Value);

            return(message);
        }