This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
51 lines (47 loc) · 1.73 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.IO;
using System.Text;
using Microsoft.Owin;
using Newtonsoft.Json;
using Owin;
namespace WebCatcher
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Run(context =>
{
WriteRequest(context.Request);
context.Response.ContentType = "text/plain";
context.Response.StatusCode = 200;
return context.Response.WriteAsync("Web Catcher says: Thank you!");
});
}
protected void WriteRequest(IOwinRequest request)
{
var defaultForegroundColor = Console.ForegroundColor;
Console.WriteLine("---------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("{0} {1}", request.Method, request.Uri.AbsoluteUri);
Console.ForegroundColor = defaultForegroundColor;
Console.WriteLine("---------------------------------------------------------------");
using (var reader = new StreamReader(request.Body))
{
var content = reader.ReadToEnd();
var formattedContent = FormatBody(request, content);
Console.WriteLine(formattedContent);
}
Console.WriteLine("---------------------------------------------------------------");
}
private static string FormatBody(IOwinRequest request, string content)
{
if (request.ContentType.Contains("json"))
{
return JsonConvert.DeserializeObject(content)
.ToString();
}
return content;
}
}
}