-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e418536
commit c2bc2e8
Showing
6 changed files
with
114 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace TodoApp.MAUI.Services; | ||
|
||
/// <summary> | ||
/// A delegating handler that logs the request/response to stdout. | ||
/// </summary> | ||
public class LoggingHandler : DelegatingHandler | ||
{ | ||
public LoggingHandler() : base() | ||
{ | ||
} | ||
|
||
public LoggingHandler(HttpMessageHandler innerHandler) : base(innerHandler) | ||
{ | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
Debug.WriteLine($"[HTTP] >>> {request.Method} {request.RequestUri}"); | ||
await WriteContentAsync(request.Content, cancellationToken); | ||
|
||
HttpResponseMessage response = await base.SendAsync(request, cancellationToken); | ||
|
||
Debug.WriteLine($"[HTTP] <<< {response.StatusCode} {response.ReasonPhrase}"); | ||
await WriteContentAsync(response.Content, cancellationToken); | ||
|
||
return response; | ||
} | ||
|
||
private static async Task WriteContentAsync(HttpContent? content, CancellationToken cancellationToken = default) | ||
{ | ||
if (content != null) | ||
{ | ||
Debug.WriteLine($"[HTTP] >>> {await content.ReadAsStringAsync(cancellationToken)}"); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters