about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-02-29 09:39:11 +0000
committerRory& <root@rory.gay>2024-02-29 09:39:11 +0000
commit2f4e8a02c27dbf36daa57e3abaab529ab6dd278a (patch)
tree644914370db6deb11f8125e13aa1841e556e68b2
parentDump content (diff)
downloadMatrixMediaGate-2f4e8a02c27dbf36daa57e3abaab529ab6dd278a.tar.xz
Dump content
-rw-r--r--MatrixMediaGate/Program.cs31
1 files changed, 28 insertions, 3 deletions
diff --git a/MatrixMediaGate/Program.cs b/MatrixMediaGate/Program.cs

index 5f39e22..1785434 100644 --- a/MatrixMediaGate/Program.cs +++ b/MatrixMediaGate/Program.cs
@@ -132,12 +132,37 @@ async Task ProxyDump(ProxyConfiguration cfg, HttpContext ctx, HttpRequestMessage Directory.CreateDirectory(dir); var path = Path.Combine(dir, $"{(int)resp?.StatusCode}-{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}-{ctx.Request.GetEncodedPathAndQuery().Replace('/', '_')}.json"); await using var file = File.Create(path); + + //collect data + JsonObject? requestJsonContent = null; + try { + requestJsonContent = await ctx.Request.ReadFromJsonAsync<JsonObject>(); + } + catch (Exception) { + // ignored, we might not have a request body... + } + + JsonObject? responseJsonContent = null; + string? responseRawContent = null; + try { + responseJsonContent = await resp.Content.ReadFromJsonAsync<JsonObject>(); + } + catch (Exception) { + try { + responseRawContent = await resp.Content.ReadAsStringAsync(); + } + catch (Exception) { + // ignored, we might not have a response body... + } + } + await JsonSerializer.SerializeAsync(file, new { Self = new { Request = new { ctx.Request.Method, Url = ctx.Request.GetEncodedUrl(), - ctx.Request.Headers + ctx.Request.Headers, + JsonContent = requestJsonContent }, Response = new { ctx.Response.StatusCode, @@ -157,8 +182,8 @@ async Task ProxyDump(ProxyConfiguration cfg, HttpContext ctx, HttpRequestMessage resp.Headers, resp.Content.Headers.ContentType, resp.Content.Headers.ContentLength, - JsonContent = resp.Content.Headers.ContentType?.MediaType == "application/json" ? await resp.Content.ReadFromJsonAsync<JsonObject>() : null, - TextContent = resp.Content.Headers.ContentType?.MediaType != "application/json" ? await resp.Content.ReadAsStringAsync() : null + JsonContent = responseJsonContent, + TextContent = responseRawContent } }, Exception = new {