-
Notifications
You must be signed in to change notification settings - Fork 165
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
Restore aspnet-request-posted-body with middleware #781
Conversation
…h and HttpContext.Items collection
Attempt to restore aspnet-request-posted-body layout renderer in NLog.Web 5.0. |
Codecov Report
@@ Coverage Diff @@
## master #781 +/- ##
=====================================
+ Coverage 63% 66% +3%
=====================================
Files 48 49 +1
Lines 790 810 +20
Branches 196 201 +5
=====================================
+ Hits 498 535 +37
+ Misses 223 197 -26
- Partials 69 78 +9
Continue to review full report at Codecov.
|
Thank you for this great contribution. Really amazing that you include both NLog.Web (HttpModule) and NLog.Web.AspNetCore (Middleware). I like the idea of using delegates, that allows the users to plugin functionality without having to inherit and override methods. Would it make sense if we created one AspNetCore-middleware for NLog, where one of the features is correctly capturing Was also thinking to make the Enable-Buffering-Condition-Logic a little "smarter", since the |
Thank you, I worked very hard on the PR. :) If you want a single middleware class that is clearly the proper goal, I did not want to change an existing class since this is my first commit to NLog.Web, but yes i thought when I was doing the PR that having > 1 middleware is not the best idea. I can do the EnableBuffering() only if > 64K change quickly, later today or tomorrow. I have used NLog heavily and would like to help enhance one of my favorite github projects. |
I examined the documentation for EnableBuffering(), it states a limit of 30K, should we try that? "Ensure the can be read multiple times. Normally buffers request bodies in memory; writes requests larger than 30K bytes to disk." |
I was also guessing that was your approach (to keep things simple and isolated before interfering with existing classes).
You have created I was thinking a similar thing could be done for |
I see what you mean now. For the EnableBuffering(), it seems like Microsoft has already done the in memory part for us: As I am using my middleware for rest and soap, i do not have a test case > 30K. |
Then I think 30K should be the default-max-limit for NLog-midddleware, and if ContentLength is larger, then it will not attempt
Very impressed. |
Well, I found that if I leave EnableBuffing() off, stream.CanSeek returns false and we cannot capture the request body since we have to reset Position property to zero, read to end, then rest the Position back to original. The unit test does not show this but actual end to end test does show this. |
ok I will make limit = 30k instead of 8 k |
Default limit changed from 8KB to 30KB per Microsoft comments on EnableBuffering() method. |
Will need help testing the IHttpModule version end to end, I do not have any legacy 4.6.2 Framework web application anymore at my team where I work. |
Will examine squeezing 2 middleware into 1 class later this week. |
…ouldCapture predicate.
… respected. Also added DetectEncodingFromByteOrderMark property.
…string.Empty, to match the Middleware version of the same class
…rty as the RequestPostedBodyMiddleware has
I think I am ready for the next review. The last commit unit tests failed due to an unrelated nuget.org error and I am researching how to rerun the checks for the last commit. |
src/Shared/LayoutRenderers/AspNetRequestPostedBodyLayoutRenderer.cs
Outdated
Show resolved
Hide resolved
src/NLog.Web.AspNetCore/NLogRequestPostedBodyMiddlewareConfiguration.cs
Outdated
Show resolved
Hide resolved
src/NLog.Web.AspNetCore/NLogRequestPostedBodyMiddlewareConfiguration.cs
Outdated
Show resolved
Hide resolved
src/NLog.Web.AspNetCore/NLogRequestPostedBodyMiddlewareConfiguration.cs
Outdated
Show resolved
Hide resolved
src/NLog.Web.AspNetCore/NLogRequestPostedBodyMiddlewareConfiguration.cs
Outdated
Show resolved
Hide resolved
src/NLog.Web.AspNetCore/NLogRequestPostedBodyMiddlewareConfiguration.cs
Outdated
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed! |
Thank you so much for being persistent and completing all my requests. I will try to add the ASP.NET Classic support using HttpModule, at least as first attempt. See also #785 |
Thank you for all of the reviews, I know you are very busy with all of the NLog work! If you need assistance with HttpModule, please let me know. Hopefully the code in the middleware gives a direction to develop the HttpModule. Microsoft makes it very hard to unit tests pre-ASP.NET Core middleware (meaning HttpModule) or HttpContext class. Maybe I can find a legacy Framework ASP.NET app at my employer that I can test with, my direct department does not but the departments we work with may have one. |
@bakgerman Would it make sense to also have a Content-Type filter, so only trying to handle posted-body when in expected-formats (Avoid images / binaries / blobs / etc.)
Alternative use https://docs.microsoft.com/en-us/dotnet/api/system.net.http.headers.mediatypeheadervalue.tryparse if (!MediaTypeHeaderValue.TryParse(contentType, out var mediaType))
{
return false;
}
if (mediaType.Charset.HasValue)
{
return true;
} |
@bakgerman Created #787 with a very primitive ContentType-filter. Would it work for you? |
Would it be possible for you to update this wiki-page, and describe the recommended way for enabling https://github.com/NLog/NLog/wiki/AspNet-Request-posted-body-layout-renderer You are very wellcome to remove all the old noise about previous version/attempts, and just state that one must use NLog.Web.AspNetCore v5.1 (or newer). |
Certainly |
I have changed it as requested. |
Could you also add details about using the options for the middleware?
|
Sure. Should we add the response body middleware as example to another page? |
Added a large section about the middleware options to the end of the page |
Looks great. Thank you again.
You are very welcome to add new wiki-page about logging the response body. Then add link from request-body-layout-wiki-page.
|
Ok I will work on that next |
This restores aspnet-request-posted-body layout renderer using middleware for asp.net core and httpmodule for legacy asp.net