Skip to content

Commit

Permalink
fixed infinite redirect (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Aug 15, 2022
1 parent d292cca commit 52edf52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions warpgate-protocol-http/src/catchall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::sync::Arc;

use poem::session::Session;
use poem::web::websocket::WebSocket;
use poem::web::{Data, FromRequest};
use poem::web::{Data, FromRequest, Redirect};
use poem::{handler, Body, IntoResponse, Request, Response};
use serde::Deserialize;
use tokio::sync::Mutex;
use tracing::*;
use warpgate_common::{Services, Target, TargetHTTPOptions, TargetOptions, WarpgateServerHandle};

use crate::common::{gateway_redirect, SessionAuthorization, SessionExt};
use crate::common::{SessionAuthorization, SessionExt};
use crate::proxy::{proxy_normal_request, proxy_websocket_request};

#[derive(Deserialize)]
Expand All @@ -18,6 +18,10 @@ struct QueryParams {
warpgate_target: Option<String>,
}

pub fn target_select_redirect() -> Response {
Redirect::temporary("/@warpgate").into_response()
}

#[handler]
pub async fn catchall_endpoint(
req: &Request,
Expand All @@ -28,7 +32,7 @@ pub async fn catchall_endpoint(
server_handle: Option<Data<&Arc<Mutex<WarpgateServerHandle>>>>,
) -> poem::Result<Response> {
let Some((target, options)) = get_target_for_request(req, services.0).await? else {
return Ok(gateway_redirect(req).into_response());
return Ok(target_select_redirect());
};

session.set_target_name(target.name.clone());
Expand Down

0 comments on commit 52edf52

Please sign in to comment.