Commit 0fe4281
committed
Subject: Refactored JSON operations and improved response writing
Body:
Replaced `System.Text` namespace with `System.Text.Json` for JSON operations. Added two private static variables, `s_Options` and `JsonContentType`, for setting JSON writer options and response content type respectively.
Converted `WriteResponse` method to asynchronous to allow non-blocking IO-bound operations. Modified `Utf8JsonWriter` to write directly to `context.Response.Body`, eliminating the need for `MemoryStream` to string conversion.
Added `foreach` loops for iterating over `result.Entries` and `entry.Value.Data` collections, enabling writing each health check entry and its data to the JSON response. Simplified `JsonSerializer.Serialize` method by removing unnecessary line breaks.
Included `writer.FlushAsync` method to ensure all buffered data is written to the underlying stream. Removed conversion of `MemoryStream` to string and writing it to the response as `Utf8JsonWriter` now writes directly to the response body.1 parent 4be488e commit 0fe4281
File tree
1 file changed
+11
-15
lines changed- src/XperienceCommunity.AspNetCore.HealthChecks
1 file changed
+11
-15
lines changedLines changed: 11 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | | - | |
| 22 | + | |
21 | 23 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
42 | | - | |
43 | | - | |
| 42 | + | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | 53 | | |
58 | 54 | | |
59 | 55 | | |
0 commit comments