Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add abillity to set path prefix #579

Closed
wants to merge 4 commits into from

Conversation

Jikstra
Copy link
Contributor

@Jikstra Jikstra commented Aug 27, 2021

This PR should replace the --random-route argument with both a --path-prefix argument and a conflicting --random-path-prefix argument.

The --random-path-prefix argument should be a fully functional replacement to --random-route.

This PR reimplements the code of @mkroman from this #208 and adds a simple test

Fixes #533

Copy link
Owner

@svenstaro svenstaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent stuff, just some minor nits. :)

Be verbose, includes emitting access logs


-D, --dirs-first
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the whitespaces here? Thanks for updating the README but let's not introduce unnecessary whitespaces.

fn serves_requests_with_path_prefix() -> Result<(), Error> {
let route = "foobar";
let server = server(&["--path-prefix", route]);
let client = Client::new();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably get away without this line by using reqwest::blocking::get directly below where you need it. This is what we do in other tests and would keep this consistent.


let status = client.get(server.url()).send()?.status();

assert_eq!(status, StatusCode::NOT_FOUND);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate a comment here about your expectation at this point in the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i don't get it. What do you mean?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, why do you expect it to be NOT_FOUND there but OK later in the test? Give it a bit of a narrative. :)

@Jikstra
Copy link
Contributor Author

Jikstra commented Sep 2, 2021

I will rebase this after #508 got merged :)

@svenstaro svenstaro mentioned this pull request Sep 16, 2021
@svenstaro
Copy link
Owner

Wanna rebase this, I'll review and then I'll cut a release?

Copy link
Contributor

@aliemjay aliemjay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some pedantic review :)

Comment on lines +59 to +60
#[structopt(long = "path-prefix")]
pub path_prefix: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to rename to "route" IMO to avoid a breaking change and to be distinguished from filesystem path!

Comment on lines +49 to +50
/// Use a random path prefix
pub random_path_prefix: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused field.

Comment on lines +112 to +113
let return_path = match state.path_prefix {
Some(ref path_prefix) => format!("/{}", path_prefix),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let return_path = match state.path_prefix {
Some(ref path_prefix) => format!("/{}", path_prefix),
let return_path = match state.path_prefix {
Some(ref path_prefix) => format!("/{}", path_prefix.trim_matches('/')),

to better handle unexpected user input.

Comment on lines +46 to +47
/// Use a specific path prefix
pub path_prefix: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this to be just String, where absent route prefix is represented as empty string. This would make it easy to use when building urls.

You may want to take a look at my previous PR 7ea3beb

Comment on lines +225 to +226
#[rstest]
fn serves_requests_with_path_prefix() -> Result<(), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another test case should be added to tests/bind.rs:validate_printed_urls.

Comment on lines +227 to +229
let route = "foobar";
let server = server(&["--path-prefix", route]);
let client = Client::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add more user input cases? I'm thinking of something like:

#[case("foo", "/foo")]
#[case("/foo", "/foo")]
#[case("/foo/", "/foo")]
fn test(#[case] prefix_arg, #[case] accessible_url) { }

@Jikstra
Copy link
Contributor Author

Jikstra commented Dec 29, 2021

Closed in favor of #682

@Jikstra Jikstra closed this Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can we specify the route digit?
3 participants