public StringResponse(HttpCodes aStatus, string aMime, string aBody) { status = aStatus; body = aBody; headers["Content-Type"] = aMime; headers["Content-Length"] = Encoding.UTF8.GetByteCount(body).ToString(); }
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]); }
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; } }
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()); }
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); }
public StringResponse(HttpCodes aStatus, string aBody) : this(aStatus, "text/html; charset=utf-8", aBody) { }
internal Redirect(HttpCodes code, Uri uri) : this(code, uri.AbsoluteUri) { }
public ResourceException(string message, HttpCodes code, ExceptionCode exceptionCode) : base(message) { _code = code; _message = message; _exceptionCode = exceptionCode; }
public ResourceResponse(HttpCodes aStatus, string type, string aResource) : this(aStatus, type, Properties.Resources.ResourceManager, aResource) { }
internal Redirect(HttpCodes code, IRequest request, string path) : this(code, string.Format("http://{0}{1}", request.LocalEndPoint, path)) { }
public UserException(string message, HttpCodes code, ErrorCodes internalCode) : base(message) { _code = code; _message = message; _internalCode = internalCode; }
public FileResponse(HttpCodes aStatus, FileInfo aBody) : this(aStatus, "text/html; charset=utf-8", aBody) { }
internal Redirect(HttpCodes code, string uri) : base(code, "text/plain", "Redirecting...") { Headers.Add("Location", uri); }
public CollectionException(string message, HttpCodes code, ExceptionCode exceptionCode) : base(message) { _code = code; _message = message; _exceptionCode = exceptionCode; }
public RijndealException(HttpCodes code, ExceptionCode exceptionCode, string message) : base(message) { _code = code; _message = message; _exceptionCode = exceptionCode; }