-
-
Notifications
You must be signed in to change notification settings - Fork 25
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 serve_files_by_extension #44
Conversation
(Oh, CI is failing because Hyper 1.0 was released hours ago. It's fixed if you merge with I'm not sure I understand what you're trying to do here. Do you have a directory with files all of the same type? In the doc comments, you show examples of serving HTML files, but the way it's implemented here, it becomes impossible to serve any other type of file, like CSS or images. Is that intended? |
Yes, I want to make a snapshot server. All the files provided are |
Ah, I see. I think as implemented here it's maybe a bit too specific for what I think the goal is for this library. I was thinking maybe a more generic rewrite functionality instead? Does something like #46 work for you? |
Hi @stephank, This is not a website static file using case, but it is still pretty general in other file-specific file-sharing services as you can see in other services. For example. RGS, https://rapidsync.lightningdevkit.org I can use In the other view, if the I hope you can consider it and accept the PR, the function name in the PR may not always be proper, and it is appreciated to have a good review on it. |
I'm not sure I follow. If you do something like this: resolver.set_rewrite(|mut params| async move {
params.path.set_extension("bin");
Ok(params)
}); It should do exactly the same as what you were trying to accomplish, though I would recommend doing something slightly different: resolver.set_rewrite(|mut params| async move {
if !params.is_dir_request && params.path.extension() != Some("bin".as_ref()) {
let mut path = params.path.into_os_string();
path.push(".bin");
params.path = path.into();
}
Ok(params)
}); That should also work for filenames with dots, e.g.
My reference for From what I understand, that does actual filesystem checks, so e.g. with options But without those checks, and by simply doing (I would accept an implementation that looks like the
#46 is not adding as much functionality or overhead as nginx rewrite or try_files. It's merely adding a function parameter that's called at a specific spot. Performance before and after #46 looks the same to me. On an AWS EC2 I don't think you can compare |
Thank you for doing a benchmark on this. 🙏 It is good to try the file We already know the |
Sorry, I wasn't clear on what I actually benchmarked, but the benchmark with #46 did include a call to I'll still merge #46, because I'm personally happy with it. But forking and using a git dependency is definitely something you can choose to do. Thanks for discussing and contributing! |
No description provided.