-
-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
addr::remote() always returns None with externally-provided TcpListener #830
Comments
You can do it by jumping through some hoops using use futures::{Future, TryFutureExt};
use hyper::{server::Server, service::make_service_fn};
use std::convert::Infallible;
use std::net::SocketAddr;
use warp::filters::BoxedFilter;
use warp::Reply;
/// Create a hyper server with the provided `filter`, binding to `addr`. This also sets the
/// `TCP_NODELAY` flag on incoming connections.
pub(crate) fn serve_it<T: Into<SocketAddr>>(
addr: T,
filter: BoxedFilter<(impl Reply + 'static,)>,
) -> anyhow::Result<(SocketAddr, impl Future<Output = anyhow::Result<()>>)> {
let filtered_service = warp::service(filter);
let make_svc = make_service_fn(move |_| {
let filtered_service = filtered_service.clone();
async move { Ok::<_, Infallible>(filtered_service) }
});
let listener: std::net::TcpListener = make_listener(addr)?;
let bound_to = listener.local_addr()?;
let builder = Server::from_tcp(listener)?;
let fut = builder.tcp_nodelay(true).serve(make_svc).map_err(|e| e.into());
Ok((bound_to, fut))
} |
@wngr I had code similar to this - unless I'm mistaken, you can't then access the |
You're right, you can't. The original issue description is misleading then though, maybe you could clarify the missing behaviour a bit more. |
Oh wow, yeah that description was unreadable looking back - sorry about that. Hopefully the updated one is a bit more readable, thanks for looking into it. |
Hope we can merge #713 before v0.4 release. |
So, what is the status on this? When is v0.4 coming? I see there are actually two concurrent implementations in PR #964 and #713. Which will be accepted? I see that #964 does not break any public interface (allegedly). Can it be shipped in a minor version? Asking this because I need it for a current project of mine. |
there's no way currently to run a warp service that depends on the
addr::remote()
filter when served from a custom-initialized TCP socket, as neitherServer::run_incoming2()
norFilteredService::call_with_addr()
are accessible from outside the crate, so even trying thewarp::service()
route doesn't help.#713 attempts to solve this one way, but it seems to have not gotten any activity.
In its simplest form, is there any reason not to simply make
FilteredService::call_with_addr()
public?The text was updated successfully, but these errors were encountered: