Skip to content

Commit

Permalink
endpoint: disabling redirect url (#1533)
Browse files Browse the repository at this point in the history
* disabling redirect url

* bump version -> 0.4.7

* commented code
  • Loading branch information
Heulitig authored Nov 28, 2023
1 parent e01310c commit 7499ef7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions fastn-core/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ pub async fn serve(
if file_response.status() == actix_web::http::StatusCode::NOT_FOUND {
// TODO: Check if path exists in dynamic urls also, otherwise pass to endpoint
// Already checked in the above method serve_file

tracing::info!("executing proxy: path: {}", &path);
let (package_name, url, mut conf) =
fastn_core::config::utils::get_clean_url(config, path.as_str())?;
Expand Down
37 changes: 19 additions & 18 deletions fastn-core/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,25 @@ impl ResponseBuilder {
{
response_builder.insert_header(header);
}
if status == actix_web::http::StatusCode::FOUND {
response_builder.status(actix_web::http::StatusCode::OK);
if let Some(location) = response.headers().get(actix_web::http::header::LOCATION) {
let redirect = location.to_str().unwrap();
let path = if redirect.trim_matches('/').is_empty() {
format!("/-/{}/", package_name)
} else {
// if it contains query-params so url should not end with /
if redirect.contains('?') {
format!("/-/{}/{}", package_name, redirect.trim_matches('/'))
} else {
format!("/-/{}/{}/", package_name, redirect.trim_matches('/'))
}
};
let t = serde_json::json!({"redirect": path.as_str()}).to_string();
return response_builder.body(t);
}
}

// if status == actix_web::http::StatusCode::FOUND && false {
// response_builder.status(actix_web::http::StatusCode::OK);
// if let Some(location) = response.headers().get(actix_web::http::header::LOCATION) {
// let redirect = location.to_str().unwrap();
// let path = if redirect.trim_matches('/').is_empty() {
// format!("/-/{}/", package_name)
// } else {
// // if it contains query-params so url should not end with /
// if redirect.contains('?') {
// format!("/-/{}/{}", package_name, redirect.trim_matches('/'))
// } else {
// format!("/-/{}/{}/", package_name, redirect.trim_matches('/'))
// }
// };
// let t = serde_json::json!({"redirect": path.as_str()}).to_string();
// return response_builder.body(t);
// }
// }

let content = match response.bytes().await {
Ok(b) => b,
Expand Down
2 changes: 1 addition & 1 deletion fastn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastn"
version = "0.4.6"
version = "0.4.7"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down

0 comments on commit 7499ef7

Please sign in to comment.