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 trailing slash back in #5

Merged
merged 2 commits into from
Mar 26, 2017

Conversation

scottmmjackson
Copy link
Contributor

There's a situation where if the server behind the proxy does the following, you can end up in an infinite redirect:

-> GET /hello
-> -> GET /hello
<- 307 TEMPORARY REDIRECT
<- Location: /hello/
-> GET /hello/
-> -> GET /hello
<- 307 TEMPORARY REDIRECT
<- Location: /hello/

etc.

Rather than try to go too far outside of your design, I altered the combinePaths helper to make a quick check to see if there was a trailing slash in the original request, and if so- to add it back.

The unit tests seem to be failing on Node 6, so I'm not sure what to do about that. Manual tests pass.

@socsieng
Copy link
Owner

Codebase is really old... given the chance, I'd do things differently. I'm in the process of updating node versions, using yarn, and massaging the tests to work with your new scenarios.

@scottmmjackson
Copy link
Contributor Author

Cool! Let me know if you'd like some extra eyes/hands. It's working great for my use case right now!

src/capture.js Outdated
@@ -30,6 +30,12 @@ function listen (appRoot, port, options) {
return !!s;
}).join('/');

// If the final argument ended with a trailing slash, return it.
var last = args.slice(-1)[0];
if (last.slice(-1) === '/') {
Copy link
Owner

Choose a reason for hiding this comment

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

So the reason for the failing test is related to when the last argument is /.

Updating the condition to read as below does the trick:

if (last !== '/' && last.slice(-1) === '/') {
    path += '/';
}

Do you mind rebasing off master and applying the suggested change?

@socsieng
Copy link
Owner

Appreciate the contribution by they way.

@scottmmjackson
Copy link
Contributor Author

I added a couple of test cases drawn to that slash issue. I had to disable one of the FS tests as it was failing on Ubuntu. I also decided to give this awful optimization a shot.

Let me know your thoughts.

@socsieng socsieng merged commit 8f0b9b4 into socsieng:master Mar 26, 2017
@socsieng
Copy link
Owner

Thanks for this. I've fixed up the failing test and published to npm as version 0.2.6.

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.

2 participants