-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fileserver: Fix try_files for directories, windows fix #3684
fileserver: Fix try_files for directories, windows fix #3684
Conversation
db4828b
to
6e56df3
Compare
FYI @mholt I added a new feature in the second commit in here (because it doesn't super make sense to be in a new PR since it sorta depends on these changes). I added a new placeholder Also did some refactoring to make this a bit simpler, and to centralize the placeholder setup in the file matcher. It could be simplified further probably, and you'll probably tell me to move the closure out... but 🤷♂️ this is what I felt like doing for now! I can clean it up further if you think this is ok. I can drop that 2nd commit if you don't want it, but I think it's useful. Some discussion here: https://caddy.community/t/how-to-determine-if-a-path-is-a-directory-or-a-file/9643/2 Also I kinda think this should go in 2.2, since it's a pretty good bug fix. |
Thanks, will look at this closer soon. Working though my backlog. 😃
If I recall correctly, file matchers are designed to match either a directory or a file based solely on whether a separator (I used |
This PR specifically fixes file matching so that if you use |
Okay, cool. But |
Because you can do Basically, things down the line might need to know whether the rewritten thing was a directory or a file, and behave differently based on that. That's the crux of the question in https://caddy.community/t/how-to-determine-if-a-path-is-a-directory-or-a-file/9643 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been looking at this most of the afternoon and I think I finally understand what is going on... it's a big change!
Thanks for the tests. I'm glad there are some. 😅
6e56df3
to
ed910d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, we're almost there I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, let's rock and roll.
Thanks for working so diligently on this!
Discussion: https://caddy.community/t/file-not-file-testing-question/9564
The gist of it is that the trailing
/
was being stripped bypath.Clean
, so the condition instrictFileExists
expecting a trailing/
indicating a directory expected wasn't working because it would never have a/
once it got there.But on top of this,
sanitizedPathJoin
had this issue as well, becausefilepath.Join
also cleans the path. I updated that code to re-add the path separator as well.I refactored the common lines between all the try policies that set up
suffix
andfullpath
into a closure for obvious reasons.And finally,
strictFileExists
was checking specifically for a trailing/
which did not work on Windows, so I changed that to use thefilepath.Separator
constant to work on Windows (I wrote and tested these changes on Windows).Note that
sanitizedPathJoin
is used infile_server browse
butpath.Join
is called before on the path, so no trailing slash should exist, so the behaviour should stay the same for that code path.