/// <inheritdoc /> public HttpResponse GetResponse(HttpRequest requestPacket, System.Diagnostics.Stopwatch currentStopwatch) { SessionData sessionData = new HttpSessionData(requestPacket); WalkableQueue <Tuple <ID, string> > unpackedUrls = UnpackUrlActions(requestPacket); HElement e = _debugNode.GetContents(sessionData, unpackedUrls.Peek()?.Item2, unpackedUrls); PageBuilder pb = new PageBuilder("LamestWebserver Debug View") { StylesheetCode = StyleSheet, Elements = { new HContainer { Elements ={ e }, Class = "main" }, new HContainer { Elements = { new HText($"LamestWebserver DebugView v{typeof(DebugResponse).Assembly.GetName().Version}") }, Class = "footer" } } }; return(new HttpResponse(requestPacket, pb.GetContent(sessionData)) { Cookies = ((HttpSessionData)(sessionData)).Cookies.ToList() }); }
/// <summary> /// Retrieves the Response from this DataResponse. /// </summary> /// <param name="sessionData">The current SessionData. (contains all kinds of information regarding HTTP-Parameters, User Handling, Cookies, etc.)</param> /// <param name="contentType">The returned ContentType of the Response.</param> /// <param name="encoding">The encoding of the returned content. Unicode by default.</param> /// <returns>Returns the response as byte array.</returns> protected override byte[] GetDataContents(HttpSessionData sessionData, out string contentType, ref Encoding encoding) { // Fill a 512x512px Bitmap with color gradients. Bitmap bitmap = new Bitmap(512, 512); for (int y = 0; y < 512; y++) { for (int x = 0; x < 512; x++) { if (Math.Sqrt(Math.Pow(x - 255, 2) + Math.Pow(y - 255, 2)) > 126f) { bitmap.SetPixel(x, y, Color.FromArgb(y / 2, (x + y) / 4, x / 2)); } else { bitmap.SetPixel(x, y, Color.FromArgb(x / 2, 255 - x / 2, 255 - (x + y) / 4)); } } } MemoryStream stream = new MemoryStream(); // Save the bitmap to a MemoryStream; bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png); // Set the content type. contentType = "image/png"; // Return the MemoryStream as byte[]. return(stream.ToArray()); }
protected override object GetResponse(HttpSessionData sessionData) { return(new { this_is = "a json response as object", easy_as = "pie" }); }