Add ConnectionContext.Items to ConnectionInfo
See original GitHub issueIs your feature request related to a problem? Please describe.
I added middleware to ConnectionBuilder in order to detect request source. Later I expected to find my data at HttpContext.Items. But I found that ConnectionContext.Items and HttpContext.Items are different objects.
webHostBuilder.ConfigureKestrel((context, options) =>
{
options.Listen(IPAddress.Parse("0.0.0.0"), 3301, listenOptions =>
{
listenOptions.Use((connectionContext, next) =>
{
connectionContext.Items.Add("kestrelEndpoint", "3301");
return next();
});
});
File.Delete("/tmp/api.socket");
options.ListenUnixSocket("/tmp/api.socket", listenOptions =>
{
listenOptions.Use((connectionContext, next) =>
{
connectionContext.Items.Add("kestrelEndpoint", "unixSocket");
return next();
});
});
});
Describe the solution you’d like
Add ConnectionContext.Items to ConnectionInfo along with ConnectionId and some other fields. So, ConnectionContext.Items will be accessible over HttpContext.Connection in middlewares and controllers. And it will be possible to pass any needed data from connection processing pipeline to request pipeline.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
ConnectionContext Class
Items. Gets or sets a key/value collection that can be used to share data within the scope of this connection.
Read more >How to add custom attributes to SQL connection string?
Method 1: Use the Application Name keyword in the connection string to pass up to 128 characters and retrieve with the APP_NAME() T-SQL...
Read more >Injecting connection context information using a persistent ...
Upon establishing the connection, you just need to create the table. Then insert whatever Key/Value pairs you like. The table will automatically ...
Read more >Connection Context Concepts
Connection Contexts. SQLJ supports connection contexts for connecting to different types of database schemas from the same application.
Read more >Connection Context | Advanced | Collaboration Kit | Tools
You can create your own connection context by implementing the ConnectionContext interface, or by using one of the provided implementations. A ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ConnectionContext is a Kestrel-specific API today. Other servers could theoretically implement the abstraction, but I’m not aware of any others that do today. As @Tratcher points out, the HTTP.Sys doesn’t give you direct control over the underlying connection making implementing the abstraction in HttpSysServer impossible.
Even in Kestrel’s case, I don’t we should combine ConnectionContext.Items and HttpContext.Items because it’s a pretty niche use case and it would technically breaking. There is a pretty easy workaround though:
To access ConnectionContext.Items and ConnectionContext.Id from request middleware, you can do something like the following:
Does this work for you @coderuid?
It’s not available in the enumeration currently but maybe it should be.