Skip to content

Commit

Permalink
Rename prepend_path to redirect_path_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
maxi0604 committed May 2, 2024
1 parent e5249a2 commit 4ead891
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions tower-http/src/services/fs/serve_dir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const DEFAULT_CAPACITY: usize = 65536;
#[derive(Clone, Debug)]
pub struct ServeDir<F = DefaultServeDirFallback> {
base: PathBuf,
prepend_path: String,
redirect_path_prefix: String,
buf_chunk_size: usize,
precompressed_variants: Option<PrecompressedVariants>,
// This is used to specialise implementation for
Expand All @@ -73,7 +73,7 @@ impl ServeDir<DefaultServeDirFallback> {

Self {
base,
prepend_path: "".to_string(),
redirect_path_prefix: "".to_string(),
buf_chunk_size: DEFAULT_CAPACITY,
precompressed_variants: None,
variant: ServeVariant::Directory {
Expand All @@ -90,7 +90,7 @@ impl ServeDir<DefaultServeDirFallback> {
{
Self {
base: path.as_ref().to_owned(),
prepend_path: "".to_string(),
redirect_path_prefix: "".to_string(),
buf_chunk_size: DEFAULT_CAPACITY,
precompressed_variants: None,
variant: ServeVariant::SingleFile { mime },
Expand Down Expand Up @@ -126,8 +126,8 @@ impl<F> ServeDir<F> {
/// redirect to `/<path>/` but instead to `/static/<path>/`
///
/// The default is the empty string.
pub fn prepend_path(mut self, path: String) -> Self {
self.prepend_path = path;
pub fn redirect_path_prefix(mut self, path: String) -> Self {
self.redirect_path_prefix = path;
self
}

Expand Down Expand Up @@ -227,7 +227,7 @@ impl<F> ServeDir<F> {
/// ```
pub fn fallback<F2>(self, new_fallback: F2) -> ServeDir<F2> {
ServeDir {
prepend_path: "".to_string(),
redirect_path_prefix: "".to_string(),
base: self.base,
buf_chunk_size: self.buf_chunk_size,
precompressed_variants: self.precompressed_variants,
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<F> ServeDir<F> {
}
};

let prepend_path = self.prepend_path.clone();
let prepend_path = self.redirect_path_prefix.clone();

let buf_chunk_size = self.buf_chunk_size;
let range_header = req
Expand Down
4 changes: 2 additions & 2 deletions tower-http/src/services/fs/serve_dir/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ async fn redirect_to_trailing_slash_on_dir() {
}

#[tokio::test]
async fn redirect_to_trailing_slash_with_prepend_path() {
let svc = ServeDir::new(".").prepend_path("/foo".to_string());
async fn redirect_to_trailing_slash_with_redirect_path_prefix() {
let svc = ServeDir::new(".").redirect_path_prefix("/foo".to_string());

let req = Request::builder().uri("/src").body(Body::empty()).unwrap();
let res = svc.oneshot(req).await.unwrap();
Expand Down

0 comments on commit 4ead891

Please sign in to comment.