tower-h2 icon indicating copy to clipboard operation
tower-h2 copied to clipboard

Support per-connection data for services

Open mzabaluev opened this issue 6 years ago • 3 comments

Sometimes it's useful to associate connection-level information with requests and/or service instances. Currently, the MakeService implementation that is passed to a Server upon construction does not receive any data for service instances to be able to distinguish transport connections. The Service instances only deal with HTTP request objects that, by design, do not provide transport information. It would be nice to be able to pass per-connection information to the services somehow.

mzabaluev avatar Apr 05 '19 07:04 mzabaluev

Some thoughts on whether this requirement is unusual. In general, there is no obligation for request streams multiplexed over a single HTTP/2 connection to belong to a single logical peer entity, and there are probably scenarios where this assumption breaks (proxies?). One important use case is TLS connections with client authentication, where trusted information about the peer can be retrieved from the connection's context.

mzabaluev avatar Apr 05 '19 11:04 mzabaluev

@mzabaluev we have been thinking about adding a Connection trait to tower-http that will bridge the gap between connection and transport, that said, it should be possible to wrap a MakeService and MakeConnection to provide the context you need.

LucioFranco avatar Apr 05 '19 14:04 LucioFranco

This is possible already in hyper, where the MakeService is provided a reference to the connection so it can collect what it needs to create a Service.

seanmonstar avatar Apr 05 '19 14:04 seanmonstar