Warp: How to redirect `upgrade` to another socket?

I want to have one entry point on my server, that will redistribute connection to servers on the same machine. For that, I need to be able to redirect upgrade request sent by the user.
So from user's perspective they connect to :3000, but in reality it goes to :44405.

I managed to do it in Node.js, where you can call handleUpgrade on the server directly. However, I have no idea how to do this in warp.

This is my best attempt, using warp::redirect(). But this requires socket to allow for redirections, and additional bounce of 3XX from the server.

This code will redirect upgrade of :8080/test to :3000/socket on the same host as requested:

let test = warp::path("test")
    .map(move |ws, host: String| {
        let requested_host = Uri::from_str(&host).unwrap();
        let host = requested_host.host().unwrap();
        let redirection_addr = "ws://".to_owned() + host + ":3000/socket";


rt.spawn(async move {
    warp::serve(test).bind(([0, 0, 0, 0], 8080)).await;

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.