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

Make SharedDataMiddleware respect order of exports #1197

Closed
wants to merge 0 commits into from

Conversation

Projects
None yet
2 participants
@snoack
Copy link
Contributor

commented Nov 19, 2017

The SharedDataMiddleware (and serving.run_simple(static_files=...) respectively) takes a dict, mapping file and directory names in the URL to files, directories or modules on disk. However, there are no dict-lookups involved in that logic, but instead dict item's are iterated, until a first match is found. But since dict items are retrieved in arbitrary order, the behavior is unpredictable, in scenarios like this:

serving.run_simple(static_files={
  '/static/': static_files_dir,
  '/': os.path.join(static_files_dir, 'index.html')
})

If the key / is yielded first, all requests resolve to index.html. Even using an OrderedDict doesn't help, since the SharedDataMiddleware internally creates another dict.

It seems to make most sense to just use lists, both to be passed in when using the API, and for the internal data structure. However, for backwards compatibility I keep supporting dict-like objects as well, in this PR.

@davidism

This comment has been minimized.

Copy link
Member

commented Nov 29, 2017

Would you rebase against master? We fixed the tests.

@davidism davidism closed this Dec 4, 2017

@davidism davidism force-pushed the snoack:master branch from b418f8d to c9e05d0 Dec 4, 2017

@davidism

This comment has been minimized.

Copy link
Member

commented Dec 4, 2017

Wait, what happened? I rebased and pushed to your branch and it wiped all the changes and closed it. There's no option to reopen.

@davidism

This comment has been minimized.

Copy link
Member

commented Dec 4, 2017

OK, sorry, I messed up and pushed the rebase without your changes, and GitHub won't let me push again because it thinks the pr is closed(?). I'll make a new PR with your commits.

@davidism

This comment has been minimized.

Copy link
Member

commented Dec 4, 2017

Might be related to having the commits on master instead of a separate branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.