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

Use StaticFileHandler when files are local #2656

Merged
merged 4 commits into from
Jul 19, 2017
Merged

Conversation

agermanidis
Copy link
Contributor

@agermanidis agermanidis commented Jul 17, 2017

Implements the set of changes described at #968, and fixes #1024.

In summary, a files_handler_class is added as an attribute to ContentsManager, specifying a custom request handler for the /files requests. For FileContentsManager, this is set to AuthenticatedFilesHandler (which is a light proxy over Tornado's StaticFileHandler).

Using tornado's StaticFileHandler class for serving local files is more efficient and enables HTTP Range requests, which are necessary for seekable video embeds (see #1024).

An additional change is made to the test_contents_manager test case to allow both text/plain
and text/plain; charset=UTF-8 as acceptable content-types. The reason being that while FilesHandler explicitly specifies the content type (here), Tornado's static file handler just sets the content type to the mime-type of the file, which doesn't include charset; overwriting that would be awkward.

This is my first time digging through this codebase so any changes/comments/suggestions would be much appreciated.

@agermanidis agermanidis changed the title Use static file handler when files are local Use StaticFileHandler when files are local Jul 17, 2017
@takluyver takluyver added this to the 5.1 milestone Jul 18, 2017
Copy link
Member

@takluyver takluyver left a comment

Choose a reason for hiding this comment

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

Thanks! This mostly looks good.

As it is effectively reverting a previous fix, I'd like @gnestor and/or @minrk to have a look at it.

@@ -95,7 +95,7 @@ def test_contents_manager(self):

r = self.request('GET', 'files/test.txt')
self.assertEqual(r.status_code, 200)
self.assertEqual(r.headers['content-type'], 'text/plain; charset=UTF-8')
Copy link
Member

Choose a reason for hiding this comment

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

This PR is effectively reverting #2402, so it will likely reintroduce #2397.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the tests are passing on Travis... It looks good to me. What says @minrk?

Copy link
Member

Choose a reason for hiding this comment

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

We can define AuthenticatedFileHandler.get_content_type to include the charset.

Copy link
Member

Choose a reason for hiding this comment

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

Are you requesting that @agermanidis does that in this PR, or suggesting that we do it separately?

@agermanidis
Copy link
Contributor Author

Thanks, I wasn't aware of get_content_type. AuthenticatedFileHandler should now set the charset properly. I reverted the test as well.

@takluyver
Copy link
Member

Thanks! @minrk @gnestor feel free to merge this if you're happy.

@gnestor gnestor merged commit 5192d72 into jupyter:master Jul 19, 2017
@gnestor
Copy link
Contributor

gnestor commented Jul 19, 2017

Thanks @agermanidis!! We appreciate your contribution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embedding local videos works imperfectly
4 participants