profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/Kahbazi/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

FritzAndFriends/BlazorWebFormsComponents 299

A collection of Blazor components that emulate the ASP.NET Web Forms controls of the same name

Kahbazi/SeoYarp 2

Some extensions on Yet another reverse proxy

Kahbazi/AspNetCore 0

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.

Kahbazi/AspNetIdentity 0

ASP.NET Identity for ASP.NET 4.x applications

Kahbazi/AspNetKatana 0

Microsoft's OWIN implementation, the Katana project

Kahbazi/BFF 0

Framework for ASP.NET Core to secure SPAs using the Backend-for-Frontend (BFF) pattern

delete branch Kahbazi/Serilog.Enrichers.Span

delete branch : kahbazi/ActivityTags

delete time in 13 hours

pull request commentdotnet/aspnetcore

Make hosting request log into struct to reduce allocation

@davidfowl Here's the allocation profile for 1000 requests. I think we could also make logging scope into readonly struct as well. Before:

Type Allocations
System.String 15,377
System.SByte[] 10,706
System.Threading.ExecutionContext 4,126
System.Byte[] 2,742
System.Threading.AsyncLocalValueMap.OneElementAsyncLocalValueMap 2,125
System.String[] 2,121
System.Threading.AsyncLocalValueMap.TwoElementAsyncLocalValueMap 2,000
System.Object 1,810
System.Collections.Concurrent.ConcurrentDictionary<,>.Node 1,322
System.Threading.CancellationTokenSource.CallbackNode 1,228
System.Threading.CancellationTokenSource.Registrations 1,195
System.IDisposable[] 1,135
Microsoft.Extensions.Logging.LoggerFactoryScopeProvider.Scope 1,125
Microsoft.Extensions.Logging.Logger.Scope 1,125
System.Runtime.CompilerServices.AsyncTaskMethodBuilder<>.AsyncStateMachineBox<> 1,011
Microsoft.AspNetCore.Hosting.HostingRequestFinishedLog 1,000
System.Diagnostics.Activity 1,000
Microsoft.AspNetCore.Hosting.HostingRequestStartingLog 1,000
Microsoft.AspNetCore.Hosting.HostingApplicationDiagnostics.Log.HostingLogScope 1,000
System.Threading.CancellationTokenSource.Linked1CancellationTokenSource 927
System.Object[] 914

After:

Type Allocations
System.String 15,363
System.SByte[] 10,740
System.Threading.ExecutionContext 4,126
System.Byte[] 2,740
System.Threading.AsyncLocalValueMap.OneElementAsyncLocalValueMap 2,125
System.String[] 2,121
System.Threading.AsyncLocalValueMap.TwoElementAsyncLocalValueMap 2,000
System.Object 1,810
System.Collections.Concurrent.ConcurrentDictionary<,>.Node 1,324
System.Threading.CancellationTokenSource.CallbackNode 1,219
System.Threading.CancellationTokenSource.Registrations 1,186
System.IDisposable[] 1,135
Microsoft.Extensions.Logging.LoggerFactoryScopeProvider.Scope 1,125
Microsoft.Extensions.Logging.Logger.Scope 1,125
System.Runtime.CompilerServices.AsyncTaskMethodBuilder<>.AsyncStateMachineBox<> 1,011
System.Diagnostics.Activity 1,000
Microsoft.AspNetCore.Hosting.HostingApplicationDiagnostics.Log.HostingLogScope 1,000
System.Threading.CancellationTokenSource.Linked1CancellationTokenSource 918
System.Object[] 914
Kahbazi

comment created time in 18 hours

pull request commentdotnet/aspnetcore

Make hosting request log into struct to reduce allocation

Did this uncover a lifetime issue in these tests?

I will investigate.

@Tratcher The problem was that the assertion for the log message is being done after the request is finished but the Message property itself is being generated on each access and as @davidfowl mentioned the struct is being copied and _cachedString would be null and each call ToString will create a new string and that's when the request is no longer available. https://github.com/dotnet/aspnetcore/blob/8b30d862de6c9146f466061d51aa3f1414ee2337/src/Servers/Kestrel/test/Interop.FunctionalTests/HttpClientHttp2InteropTests.cs#L1115 https://github.com/dotnet/aspnetcore/blob/45222c12d944a8915ba480220de8a1f9c133c0c4/src/Testing/src/Logging/WriteContext.cs#L24-L30

I think this could be fixed by storing the result of formatter when creating an instance of WriteContext, but I'm not sure if it's necessary for now.

Making the HostingRequestFinishedLog readonly struct and moving the creation of the formatted string in the constructor fixed the tests. @davidfowl Does it also fixes the problems you've mentioned?

Kahbazi

comment created time in a day

push eventKahbazi/AspNetCore

Kahbazi

commit sha d8d344523b44ce2f219919c66b294460ed3d180d

readonly struct

view details

push time in a day

Pull request review commentmicrosoft/reverse-proxy

Add request transform extension method

 public static class IHttpForwarderExtensions              return forwarder.SendAsync(context, destinationPrefix, httpClient, requestConfig, HttpTransformer.Default);         }++        /// <summary>+        /// Forwards the incoming request to the destination server, and the response back to the client.+        /// </summary>+        /// <param name="context">The HttpContext to forward.</param>+        /// <param name="destinationPrefix">The url prefix for where to forward the request to.</param>+        /// <param name="httpClient">The HTTP client used to forward the request.</param>+        /// <param name="requestTransform">Delegate to apply to forwarded the request.</param>+        /// <returns>The result of forwarding the request and response.</returns>

This is the current summary for the existing extension methods. Should I change those?

Kahbazi

comment created time in a day

PullRequestReviewEvent

push eventKahbazi/reverse-proxy

Kahbazi

commit sha a866d7910662125e3165836d4899a562b1693660

Add extensions method for HttpForwarder in sample

view details

push time in a day

Pull request review commentdotnet/aspnetcore

Implement GetClientCertAsync, ApplicationProtocol

 namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal {     internal sealed partial class QuicConnectionContext : IProtocolErrorCodeFeature, ITlsConnectionFeature     {+        private X509Certificate2? _clientCert;+        private Task<X509Certificate2?>? _clientCertTask;+         public long Error { get; set; }          // Support accessing client certificate         // https://github.com/dotnet/aspnetcore/issues/34756         public X509Certificate2? ClientCertificate         {-            get => throw new NotSupportedException();-            set => throw new NotSupportedException();+            get { return _clientCert ??= ConvertToX509Certificate2(_connection.RemoteCertificate); }+            set { _clientCert = value; }

Should this also set the _clientCertTask?

            set 
            {
                 _clientCert = value; 
                 _clientCertTask = Task.FromResult(value);
             }
wtgodbe

comment created time in a day

PullRequestReviewEvent

Pull request review commentdotnet/aspnetcore

Update ExceptionHandler middleware pipeline construction to reinvoke UseRouting in error branch

 public static IApplicationBuilder UseRouting(this IApplicationBuilder builder)                 throw new ArgumentNullException(nameof(builder));             } +            return UseRouting(builder, true);+        }++        /// <summary>+        /// Adds a <see cref="EndpointRoutingMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>.+        /// </summary>+        /// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>+        /// <param name="overrideEndpointRouteBuilder">Whether a new <see cref="EndpointRouteBuilder"/> should be created.</param>+        /// <returns>A reference to this instance after the operation has completed.</returns>+        /// <remarks>+        /// <para>+        /// A call to <see cref="UseRouting(IApplicationBuilder)"/> must be followed by a call to+        /// <see cref="UseEndpoints(IApplicationBuilder, Action{IEndpointRouteBuilder})"/> for the same <see cref="IApplicationBuilder"/>+        /// instance.+        /// </para>+        /// <para>+        /// The <see cref="EndpointRoutingMiddleware"/> defines a point in the middleware pipeline where routing decisions are+        /// made, and an <see cref="Endpoint"/> is associated with the <see cref="HttpContext"/>. The <see cref="EndpointMiddleware"/>+        /// defines a point in the middleware pipeline where the current <see cref="Endpoint"/> is executed. Middleware between+        /// the <see cref="EndpointRoutingMiddleware"/> and <see cref="EndpointMiddleware"/> may observe or change the+        /// <see cref="Endpoint"/> associated with the <see cref="HttpContext"/>.+        /// </para>+        /// </remarks>+        public static IApplicationBuilder UseRouting(this IApplicationBuilder builder, bool overrideEndpointRouteBuilder)+        {+            if (builder == null)+            {+                throw new ArgumentNullException(nameof(builder));+            }+             VerifyRoutingServicesAreRegistered(builder); -            var endpointRouteBuilder = new DefaultEndpointRouteBuilder(builder);-            builder.Properties[EndpointRouteBuilder] = endpointRouteBuilder;+            IEndpointRouteBuilder endpointRouteBuilder;+            if (overrideEndpointRouteBuilder)+            {+                endpointRouteBuilder = new DefaultEndpointRouteBuilder(builder);+                builder.Properties[EndpointRouteBuilder] = endpointRouteBuilder;+            }+            else+            {+                if (builder.Properties.TryGetValue(EndpointRouteBuilder, out var routeBuilder))+                {+                    endpointRouteBuilder = (IEndpointRouteBuilder)routeBuilder!;+                }+                else+                {+                    endpointRouteBuilder = new DefaultEndpointRouteBuilder(builder);+                    builder.Properties[EndpointRouteBuilder] = endpointRouteBuilder;+                }+            }
            if (overrideEndpointRouteBuilder || !builder.Properties.TryGetValue(EndpointRouteBuilder, out var routeBuilder))
            {
                endpointRouteBuilder = new DefaultEndpointRouteBuilder(builder);
                builder.Properties[EndpointRouteBuilder] = endpointRouteBuilder;
            }
            else
            {
                endpointRouteBuilder = (IEndpointRouteBuilder)routeBuilder!;
            }
JunTaoLuo

comment created time in a day

Pull request review commentdotnet/aspnetcore

Update ExceptionHandler middleware pipeline construction to reinvoke UseRouting in error branch

 public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder a                 throw new ArgumentNullException(nameof(options));             } -            return app.UseMiddleware<ExceptionHandlerMiddleware>(Options.Create(options));+            return app.Use(next =>+            {+                var loggerFactory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();+                var diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();+                var endpointDataSource = app.ApplicationServices.GetRequiredService<EndpointDataSource>();++                if (!string.IsNullOrEmpty(options.ExceptionHandlingPath) && options.ExceptionHandler is null)+                {+                    var errorBuilder = app.New();+                    errorBuilder.UseRouting(overrideEndpointRouteBuilder: false);+                    errorBuilder.Run(next);+                    options.ExceptionHandler = errorBuilder.Build();

This is creating a new instance of options, applicationBuilder, request delegate and the middlewares per request. Why not moving this code in ExceptionHandlerMiddleware ctor? The downside is that IApplicationBuilder must be added to its ctor parameters which is a breaking change.

JunTaoLuo

comment created time in a day

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentRehanSaeed/Serilog.Enrichers.Span

Add Activity Tags Enricher

+namespace Serilog.Enrichers.Span+{+    /// <summary>+    /// Options.+    /// </summary>+    public class SpanOptions+    {+        /// <summary>+        /// Gets or sets a value indicating whether to include tags in log or not.+        /// </summary>+        public bool IncludeTags { get; set; }

Setting this to false would trigger a warning, since the default value would be false.

Kahbazi

comment created time in a day

PullRequestReviewEvent

push eventKahbazi/Serilog.Enrichers.Span

Kahbazi

commit sha bae8ac5eae79f636f923ee278c11cc3df7da5f85

Add Activity tag enricher

view details

push time in 2 days

pull request commentdotnet/aspnetcore

Make hosting request log into struct to reduce allocation

Did this uncover a lifetime issue in these tests?

I will investigate.

We can't make this change because the struct is mutable (we assign ToString to the _cachedToString) every single time. It's also less efficient since we'd need to pass a copy to each provider instead of the struct instance. Each call ToString will allocate a new string per provider instead of one for all providers.

How about making them readonly struct like FormattedLogValues?

Kahbazi

comment created time in 2 days

push eventKahbazi/reverse-proxy

Kahbazi

commit sha 96d28c064e6a61fd721075c4cd57632f7ea23e64

Add request transform extension method

view details

push time in 2 days

PR opened microsoft/reverse-proxy

Add request transform extension method

Fixes https://github.com/microsoft/reverse-proxy/issues/1172

+50 -0

0 comment

2 changed files

pr created time in 2 days

create barnchKahbazi/reverse-proxy

branch : kahbazi/ForwarderDelegate

created branch time in 2 days

create barnchKahbazi/AspNetCore

branch : kahbazi/structLogFormatter

created branch time in 2 days

push eventKahbazi/Serilog.Enrichers.Span

Arvin Kahbazi

commit sha 305a99fa9bdde80a8cbbc9779153f3bb8c3ef3c6

Review feedback

view details

push time in 3 days

Pull request review commentdotnet/aspnetcore

Improve support for OpenAPI in minimal actions

 public ProducesResponseTypeAttribute(Type type, int statusCode)         internal bool IsResponseTypeSetByDefault { get; }          /// <inheritdoc />-        void IApiResponseMetadataProvider.SetContentTypes(MediaTypeCollection contentTypes)+        public void SetContentTypes(MediaTypeCollection contentTypes)         {-            // Users are supposed to use the 'Produces' attribute to set the content types that an action can support.+            contentTypes.Clear();+            foreach (var contentType in ContentTypes)+            {+                contentTypes.Add(contentType);+            }+        }++        private MediaTypeCollection GetContentTypes(string contentType, string[] additionalContentTypes)
        private static MediaTypeCollection GetContentTypes(string contentType, string[] additionalContentTypes)
captainsafia

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentdotnet/aspnetcore

Improve support for OpenAPI in minimal actions

+// 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.Builder;+using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.Routing;++namespace Microsoft.AspNetCore.Http+{+    /// <summary>+    /// Extension methods for adding response type metadata to endpoints.+    /// </summary>+    public static class OpenApiEndpointConventionBuilderExtensions+    {+        private static readonly SuppressApiMetadata _suppressApiMetadata = new();+        /// <summary>+        /// Adds metadata to support suppressing OpenAPI documentation from+        /// being generated for this endpoint.

?

        /// Adds metadata to support suppressing OpenAPI documentation from
        /// being generated for these endpoints.
captainsafia

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentdotnet/aspnetcore

Improve support for OpenAPI in minimal actions

+// 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.Builder;+using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.Routing;++namespace Microsoft.AspNetCore.Http+{+    /// <summary>+    /// Extension methods for adding response type metadata to endpoints.+    /// </summary>+    public static class OpenApiEndpointConventionBuilderExtensions+    {+        private static readonly SuppressApiMetadata _suppressApiMetadata = new();+        /// <summary>+        /// Adds metadata to support suppressing OpenAPI documentation from+        /// being generated for this endpoint.+        /// </summary>+        /// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>+        /// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>+        public static IEndpointConventionBuilder SuppressApi(this IEndpointConventionBuilder builder)
        public static TBuilder SuppressApi<TBuilder>(this TBuilderbuilder) where TBuilder : IEndpointConventionBuilder

Why not use the same pattern like other methods for adding metadata?

captainsafia

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentdotnet/aspnetcore

Improve support for OpenAPI in minimal actions

+// 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.Builder;+using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.Routing;++namespace Microsoft.AspNetCore.Http+{+    /// <summary>+    /// Extension methods for adding response type metadata to endpoints.+    /// </summary>+    public static class OpenApiEndpointConventionBuilderExtensions+    {+        private static readonly SuppressApiMetadata _suppressApiMetadata = new();
        private static readonly SuppressApiMetadata _suppressApiMetadata = new();
        
captainsafia

comment created time in 5 days