Skip to content

Commit

Permalink
fix(dgw): ensure mime-type is set in /jet/jrec/pull (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenoit authored May 8, 2023
1 parent 9889210 commit 66dc4e3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion devolutions-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ngrok = "0.11.3"
hyper = "0.14.26"
axum = { version = "0.6.18", default-features = false, features = ["http1", "json", "ws", "query", "tracing", "tower-log", "headers"] }
axum-extra = { version = "0.7.4", features = ["query", "async-read-body"] }
tower-http = { version = "0.4.0", features = ["cors"] }
tower-http = { version = "0.4.0", features = ["cors", "fs"] }

# OpenAPI generator
utoipa = { version = "3.3.0", default-features = false, features = ["uuid", "chrono"], optional = true }
Expand Down
20 changes: 14 additions & 6 deletions devolutions-gateway/src/api/jrec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use std::sync::Arc;
use anyhow::Context as _;
use axum::extract::ws::WebSocket;
use axum::extract::{self, ConnectInfo, Query, State, WebSocketUpgrade};
use axum::response::{IntoResponse as _, Response};
use axum::response::Response;
use axum::routing::get;
use axum::{Json, Router};
use tokio::fs::File;
use tracing::Instrument as _;
use uuid::Uuid;

Expand Down Expand Up @@ -141,11 +140,17 @@ pub(crate) async fn list_recordings(
),
security(("jrec_token" = ["pull"])),
))]
pub(crate) async fn pull_recording_file(
pub(crate) async fn pull_recording_file<ReqBody>(
State(DgwState { conf_handle, .. }): State<DgwState>,
extract::Path((id, filename)): extract::Path<(Uuid, String)>,
JrecToken(claims): JrecToken,
) -> Result<Response, HttpError> {
request: axum::http::Request<ReqBody>,
) -> Result<Response<tower_http::services::fs::ServeFileSystemResponseBody>, HttpError>
where
ReqBody: Send + 'static,
{
use tower::ServiceExt as _;

if filename.contains("..") || filename.contains('/') || filename.contains('\\') {
return Err(HttpError::bad_request().msg("invalid file name"));
}
Expand All @@ -164,7 +169,10 @@ pub(crate) async fn pull_recording_file(
return Err(HttpError::not_found().msg("requested file does not exist"));
}

let file = File::open(path).await.map_err(HttpError::internal().err())?;
let response = tower_http::services::ServeFile::new(path)
.oneshot(request)
.await
.map_err(HttpError::internal().err())?;

Ok(axum_extra::body::AsyncReadBody::new(file).into_response())
Ok(response)
}

0 comments on commit 66dc4e3

Please sign in to comment.