In this post I review the way Kestrel serves HTTP requests. Please note, that the architecture described here may change from release to release of ASP.NET Core. At the time of writing .NET 7 and the corresponding ASP.NET Core is a month away from release.
Accepting connection on HTTP2 and HTTP3
ASP.NET Core's Kestrel opens
IConnectionListener<T>s upon startup. For each
ASPNETCORE_URLS set, a connection listener is instantiated. A base
IConnectionListener implementation is a
SocketConnectionListener. Connection listeners implement the decorator pattern. For example,
GenericConnectionListener expects another connection listener as a constructor parameter.Connection listeners provide basic functionality to bind/unbind to a given port and to accept new connection requests.
ConnectionDispatcher also initiated during startup. It starts to run an infinite
while loop in
AcceptConnectionsAsync() method to accept new connections on a given listener. When a client sends a request, a new connection in initialized. In this case a
KestrelConnection<T>, that also implements
Find out more