-
Notifications
You must be signed in to change notification settings - Fork 10.4k
HttpLoggingMiddleware + Websockets/Upgrade #40841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+324
−2
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6a8ce4b
Implemented UpgradeFeatureLoggingDecorator class to be used in HttpLo…
gfr-g 3de2e61
HttpLoggingMiddleware now logs connection upgrades responses as soon …
gfr-g d982946
Merge branch 'main' into issue/31962
gfr-g e991aa6
Merge branch 'dotnet:main' into issue/31962
gfr-g e2d9485
Corrected coding style
gfr-g 79a19b7
Merge branch 'main' into issue/31962
gfr-g ba73569
Merge branch 'main' into issue/31962
gfr-g 85e4959
Check for ResponseStatusCode and ResponseHeaders individually before …
gfr-g b77459e
Added tests to make sure no logs are written if HttpLoggingFields is …
gfr-g 5e6b7fd
Added check to make handle the case of an upgrade request that doesn'…
gfr-g 9a6b45d
Rename variable according to suggestion.
gfr-g 9e74fdf
Merge branch 'main' into issue/31962
gfr-g 22e5edc
Refactored UpgradeFeatureLoggingDecorator
gfr-g ed3233a
Removed redundant check
gfr-g 770e88f
Refactored method names
gfr-g 39233f9
Delete junit.xml
gfr-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
src/Middleware/HttpLogging/src/UpgradeFeatureLoggingDecorator.cs
This file contains hidden or 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,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.AspNetCore.HttpLogging; | ||
|
||
internal sealed class UpgradeFeatureLoggingDecorator : IHttpUpgradeFeature | ||
{ | ||
private readonly IHttpUpgradeFeature _innerUpgradeFeature; | ||
private readonly HttpResponse _response; | ||
private readonly HttpLoggingOptions _options; | ||
private readonly ILogger _logger; | ||
|
||
private bool _isUpgraded; | ||
|
||
public UpgradeFeatureLoggingDecorator(IHttpUpgradeFeature innerUpgradeFeature, HttpResponse response, HttpLoggingOptions options, ILogger logger) | ||
{ | ||
_innerUpgradeFeature = innerUpgradeFeature ?? throw new ArgumentNullException(nameof(innerUpgradeFeature)); | ||
_response = response ?? throw new ArgumentNullException(nameof(response)); | ||
_options = options ?? throw new ArgumentNullException(nameof(options)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public bool IsUpgradableRequest => _innerUpgradeFeature.IsUpgradableRequest; | ||
|
||
public bool IsUpgraded { get => _isUpgraded; } | ||
|
||
public async Task<Stream> UpgradeAsync() | ||
{ | ||
var upgradeStream = await _innerUpgradeFeature.UpgradeAsync(); | ||
|
||
_isUpgraded = true; | ||
|
||
HttpLoggingMiddleware.LogResponseHeaders(_response, _options, _logger); | ||
|
||
return upgradeStream; | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.