-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Check extensions on a directory before redirecting #107
base: master
Are you sure you want to change the base?
Conversation
index.js
Outdated
@@ -612,14 +612,16 @@ SendStream.prototype.sendFile = function sendFile(path) { | |||
|
|||
debug('stat "%s"', path); | |||
fs.stat(path, function onstat(err, stat) { | |||
if (err && err.code === 'ENOENT' | |||
var isDirectory = stat && stat.isDirectory(); |
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.
Stat will be undefined
if there's an err
.
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.
That's why I prefixed it with stat &&
. That's idiomatic, right?
Hi! Thanks for your pull request, but it does not include any tests for the change you made, does not include documentation, and even breaks existing tests. According to the tests this change broke, this change is actually breaking a feature of this module. Can you explain more what you change is doing, how it compares to the current functionality, and why it breaking our existing tests? |
I changed the tests to reflect what I mean and fixed an issue. |
According to the CI, this is only failing on node 0.8 now due to some package.json parsing thing. I've written a test, modified a test, and made sure all the existing tests pass. Could you please consider this PR for the next release? |
Hi @cag! It looks like you never actually answered all my questions in #107 (comment) . So, since I didn't get an answer, I can only make assumptions on what you are trying to do based on the code changes. This is a breaking change and will have to wait for the next major version at some point. Currently directories are preferred over extension-less files, and changing this will not be a backwards-compatible change. |
Sorry, I was a bit headstrong and forgot to elaborate. You're right that this change may potentially break distributions that depend on this package, but my feeling is that the behavior change is the natural one. I changed the behavior of the extensions option so that for this:
with Currently, I changed the description for one of your tests to reflect the above, but I have fixed my code changes so that they don't break your tests. |
Thanks, @cag! Yes, this change makes sense. The reason I bring up the it being a breaking change is because this conflict was known about when the extensions feature was added and it was decided at the time to prefer the directory over looking for a file with the given extension. Because of this history, I see your PR here as a proposal to change that behavior, not a bug fix. I hope that makes sense. |
That's totally fine. I didn't think of it as a bugfix. This is just the scenario I personally ran into in the wild. |
I decided to change the behavior on the send module in a project and discovered that I really wanted sendFile to send things.json for a GET request to things when stuff like things/1.json exist.