Closed danwilliams closed 7 months ago
Hello, I am having the exact same problem here.
julien-leclercq commented 5 hours ago @danwilliams It works for me if I use the same pattern as here https://github.com/tower-rs/tower-http/blob/master/examples/axum-key-value-store/src/main.rs#L62-L92
@julien-leclercq agreed, but that's not the subject of this bug report. That example uses DefaultOnResponse
, whereas the problem I have reported is when using a closure.
The above example seems to be working fine with v0.5.0
Maybe this particular example is working now but the underlying problem is still there, I get a similar error adding
.on_response(|response: &Response, latency: Duration, span: &Span| {
tracing::debug!("response generated in {:?}", latency)
})
which is copypasted from docs
Looks like 0.5.1 fixed it, at least in my case
I'll close this for now given the two reports of things working with 0.5.x. However if there are still people who need it fixed on 0.4.x, please let me know. If you could provide a repository / tarball with a crate that reproduces the problem, that would be appreciated!
Bug Report
Version
Platform
Not relevant, but Linux (Ubuntu 23.10 64-bit).
Crates
Description
Using the example provided in the latest documentation, using an
on_response()
closure does not compile.Here is a minimal example to reproduce it:
If you delete the
layer()
, i.e. lines 13-33, it compiles and runs just fine. However, using these lines fails with the following error:Notes
Note that the lines have been taken from the documentation unmodified.
Note also that they are not all required for the error to occur - this is enough:
However, I wanted to make it clear in this report that not only is this the focal point but also that using the entire example makes no difference (not that it should, but, good to be thorough).
Finally, note that although I am using Axum, I did also try specifically using the
hyper::Body
and got exactly the same problem, so it's not an Axum issue.As a side note, I had spent several hours picking through some code that I've been writing, which was not working, before tracking down the root cause of the problem and realising that it is illustrated by this example in the documentation. Hence I've used this example for the bug report, as it's very clear and shows that the documented approach causes the error, but in reality what I'm doing that made me stumble upon this is a little different (yet suffers the same cause). I was semi-relieved to find that it was a bug in tower and not my code, but also somewhat surprised 🙂