예제 #1
0
        public StringResponse(HttpCodes aStatus, string aMime, string aBody)
        {
            status = aStatus;
            body   = aBody;

            headers["Content-Type"]   = aMime;
            headers["Content-Length"] = Encoding.UTF8.GetByteCount(body).ToString();
        }
예제 #2
0
        public FileResponse(HttpCodes aStatus, string aMime, FileInfo aBody)
        {
            status = aStatus;
              body = aBody;

              headers["Content-Type"] = aMime;
              headers["Content-Length"] = body.Length.ToString();
        }
예제 #3
0
        public StringResponse(HttpCodes aStatus, string aMime, string aBody)
        {
            status = aStatus;
              body = aBody;

              headers["Content-Type"] = aMime;
              headers["Content-Length"] = Encoding.UTF8.GetByteCount(body).ToString();
        }
예제 #4
0
        public FileResponse(HttpCodes aStatus, string aMime, FileInfo aBody)
        {
            status = aStatus;
            body   = aBody;

            headers["Content-Type"]   = aMime;
            headers["Content-Length"] = body.Length.ToString();
        }
 protected override void DeserializeStartLine(string line)
 {
     string[] words = line.Split(" ");
     if (words.Length < 2)
     {
         throw new Exception("Invalid input");
     }
     protocol     = words[0];
     responseCode = (HttpCodes)int.Parse(words[1]);
 }
예제 #6
0
        public ResourceResponse(HttpCodes aStatus, string type, ResourceManager aResourceManager, string aResource)
        {
            status = aStatus;
            try {
                resource = aResourceManager.GetObject(aResource) as byte[];

                headers["Content-Type"]   = type;
                headers["Content-Length"] = resource.Length.ToString();
            }
            catch (Exception ex) {
                Error("Failed to prepare resource " + aResource, ex);
                throw;
            }
        }
예제 #7
0
        public ResourceResponse(HttpCodes aStatus, string type, ResourceManager aResourceManager, string aResource)
        {
            status = aStatus;
              try {
            resource = aResourceManager.GetObject(aResource) as byte[];

            headers["Content-Type"] = type;
            headers["Content-Length"] = resource.Length.ToString();
              }
              catch (Exception ex) {
            Error("Failed to prepare resource " + aResource, ex);
            throw;
              }
        }
예제 #8
0
        public static void Write(TextWriter writer)
        {
            TotalTime = TotalTimes.Sum();

            var elapsed = DateTime.UtcNow - Start;
            var avg     = TotalTime / TotalCount;

            Array.Sort(QuantileSample);

            writer.WriteLine("Requests/sec:    {0}", (TotalCount / (elapsed.TotalSeconds + 0.000001)).ToStdString());
            writer.WriteLine("Min time:        {0} ms", MinTime.TicksToMs());
            writer.WriteLine("Max time:        {0} ms", MaxTime.TicksToMs());
            writer.WriteLine("Avg time:        {0} ms", avg.TicksToMs());
            writer.WriteLine("Median time:     {0} ms", QuantileSample[QuantileSample.Length >> 1].TicksToMs());
            writer.WriteLine("Std deviation:   {0}", Math.Sqrt((double)QuantileSample.Sum(time => (time - avg) * (time - avg)) / (QuantileSample.Length - 1)).TicksToMs().ToStdString(suffix: "ms"));
            writer.WriteLine();
            writer.WriteLine("Time taken:      {0}", elapsed.TotalSeconds.ToStdString(suffix: "sec"));
            writer.WriteLine("Data received:   {0}", TotalBytes.ToSmartString(suffix: "B"));
            writer.WriteLine("Transfer rate:   {0}", (TotalBytes / (elapsed.TotalSeconds + 0.000001)).ToSmartString(suffix: "B/sec"));
            writer.WriteLine();

            writer.WriteLine("=== http status codes ===");
            HttpCodes.OrderBy(pair => pair.Key).ForEach(pair => writer.WriteLine("{0,10}\t{1,-10}\t{2}", pair.Value, pair.Key == 0 ? "Unknown error" : ((int)pair.Key).ToString(), ((double)pair.Value / TotalCount).ToPercentString()));
            writer.WriteLine();

            writer.WriteLine("=== quantiles ===");
            for (int i = 0; i < Quantiles.Length; i++)
            {
                var quantile = Quantiles[i];
                writer.WriteLine("{0,10}\t{1} ms", quantile.ToPercentString(), QuantileSample[Math.Max(1, quantile * QuantileSample.Length / 100) - 1].TicksToMs());
            }
            writer.WriteLine();

            long sum = 0;

            writer.WriteLine("=== times ===");
            for (int i = 0; i < Marks.Length; i++)
            {
                sum += TotalCounts[i];
                writer.WriteLine("{0,10}\t{1,-10}\t{2}", TotalCounts[i], $"<{(Marks[i] == long.MaxValue ? "inf" : Marks[i].TicksToMs().ToString())} ms", ((double)sum / TotalCount).ToPercentString());
            }
            writer.WriteLine("----------");
            writer.WriteLine("{0,10}\t{1,-10}\t{2}", TotalCount, $"<{MaxTime.TicksToMs()} ms", 1.0.ToPercentString());
        }
예제 #9
0
        public static long Update(HttpResult result)
        {
            var ticks = result.ElapsedTicks;

            Interlocked.Add(ref TotalBytes, result.BytesReceived);
            var index = Interlocked.Increment(ref TotalCount) - 1;

            if (index % QuantileMod == 0)
            {
                QuantileSample[index / QuantileMod % QuantileSample.Length] = ticks;
            }

            long min;

            while ((min = Interlocked.Read(ref MinTime)) > ticks && Interlocked.CompareExchange(ref MinTime, ticks, min) != min)
            {
                ;
            }

            long max;

            while ((max = Interlocked.Read(ref MaxTime)) < ticks && Interlocked.CompareExchange(ref MaxTime, ticks, max) != max)
            {
                ;
            }

            HttpCodes.AddOrUpdate(result.StatusCode, 1, (code, count) => count + 1);

            var idx = Array.BinarySearch(Marks, ticks);

            if (idx < 0)
            {
                idx = ~idx;
            }

            Interlocked.Add(ref TotalTimes[idx], ticks);
            Interlocked.Increment(ref TotalCounts[idx]);

            return(index);
        }
예제 #10
0
 public StringResponse(HttpCodes aStatus, string aBody)
     : this(aStatus, "text/html; charset=utf-8", aBody)
 {
 }
예제 #11
0
 internal Redirect(HttpCodes code, Uri uri)
     : this(code, uri.AbsoluteUri)
 {
 }
예제 #12
0
 public ResourceException(string message, HttpCodes code, ExceptionCode exceptionCode) : base(message)
 {
     _code          = code;
     _message       = message;
     _exceptionCode = exceptionCode;
 }
예제 #13
0
 public ResourceResponse(HttpCodes aStatus, string type, string aResource)
     : this(aStatus, type, Properties.Resources.ResourceManager, aResource)
 {
 }
예제 #14
0
 internal Redirect(HttpCodes code, IRequest request, string path)
     : this(code, string.Format("http://{0}{1}", request.LocalEndPoint, path))
 {
 }
예제 #15
0
 public UserException(string message, HttpCodes code, ErrorCodes internalCode) : base(message)
 {
     _code         = code;
     _message      = message;
     _internalCode = internalCode;
 }
예제 #16
0
 public FileResponse(HttpCodes aStatus, FileInfo aBody)
     : this(aStatus, "text/html; charset=utf-8", aBody)
 {
 }
예제 #17
0
 internal Redirect(HttpCodes code, string uri)
     : base(code, "text/plain", "Redirecting...")
 {
     Headers.Add("Location", uri);
 }
예제 #18
0
 public FileResponse(HttpCodes aStatus, FileInfo aBody)
     : this(aStatus, "text/html; charset=utf-8", aBody)
 {
 }
예제 #19
0
 internal Redirect(HttpCodes code, Uri uri)
     : this(code, uri.AbsoluteUri)
 {
 }
예제 #20
0
 public ResourceResponse(HttpCodes aStatus, string type, string aResource)
     : this(aStatus, type, Properties.Resources.ResourceManager, aResource)
 {
 }
예제 #21
0
 internal Redirect(HttpCodes code, IRequest request, string path)
     : this(code, string.Format("http://{0}{1}", request.LocalEndPoint, path))
 {
 }
 public CollectionException(string message, HttpCodes code, ExceptionCode exceptionCode) : base(message)
 {
     _code          = code;
     _message       = message;
     _exceptionCode = exceptionCode;
 }
예제 #23
0
 public StringResponse(HttpCodes aStatus, string aBody)
     : this(aStatus, "text/html; charset=utf-8", aBody)
 {
 }
예제 #24
0
 public RijndealException(HttpCodes code, ExceptionCode exceptionCode, string message) : base(message)
 {
     _code          = code;
     _message       = message;
     _exceptionCode = exceptionCode;
 }
예제 #25
0
 internal Redirect(HttpCodes code, string uri)
     : base(code, "text/plain", "Redirecting...")
 {
     Headers.Add("Location", uri);
 }