예제 #1
0
        public object Execute(RequestInfo request)
        {
            var ipAddr = HttpContext.Current.Request.UserHostAddress;

            var response = new RequestInfoResponse {
                EnpointAttributes = RequestContext.EndpointAttributes.ToString().Split(',').ToList().ConvertAll(x => x.Trim()),
                IpAddress         = ipAddr,
                IpAddressFamily   = ipAddr,
                NetworkLog        = GetNetworkLog(),
                Ipv4Addresses     = GetIpv4Addresses(),
                Ipv6Addresses     = GetIpv6Addresses(),
            };

            var requestAttr = RequestContext.RequestAttributes;

            if (requestAttr.AcceptsDeflate)
            {
                response.RequestAttributes.Add(requestAttr.AcceptsDeflate.ToString());
            }

            if (requestAttr.AcceptsGzip)
            {
                response.RequestAttributes.Add(requestAttr.AcceptsGzip.ToString());
            }

            return(response);
        }
예제 #2
0
        public void DoRequestInfo(string hostName, string hostPath, string baseUrl, IEnumerable <string> testPaths)
        {
            foreach (var testPath in testPaths)
            {
                var requestUrl = PathUtils.CombinePaths(baseUrl, testPath);
                RequestInfoResponse requestInfo = null;

                try
                {
                    var webReq = (HttpWebRequest)WebRequest.Create(requestUrl);
                    webReq.Accept = ContentType.Json;
                    var webRes = (HttpWebResponse)webReq.GetResponse();

                    var contents = new StreamReader(webRes.GetResponseStream()).ReadToEnd();

                    if (webRes.ContentType.StartsWith(ContentType.Json))
                    {
                        requestInfo = JsonSerializer.DeserializeFromString <RequestInfoResponse>(contents);
                    }
                    else
                    {
                        requestInfo = new RequestInfoResponse
                        {
                            Host        = requestUrl,
                            Path        = testPath,
                            ContentType = webRes.ContentType,
                        };
                    }
                    requestInfo.Host          = "<h4><b>" + testPath + "</b></h4>" + requestInfo.Host;
                    requestInfo.Status        = (int)webRes.StatusCode;
                    requestInfo.ContentLength = webRes.ContentLength;
                }
                catch (Exception ex)
                {
                    requestInfo = new RequestInfoResponse
                    {
                        Host         = "<h4><b>" + testPath + "</b></h4>" + requestUrl,
                        Path         = testPath,
                        ErrorCode    = ex.GetType().Name,
                        ErrorMessage = ex.Message,
                        Status       = 600,
                    };
                    var webEx = ex as WebException;
                    if (webEx != null)
                    {
                        requestInfo.Status = (int)webEx.Status;
                    }
                }
                finally
                {
                    DbFactory.Exec(dbCmd => dbCmd.Save(requestInfo));
                }
            }
        }