Part of canonical.launchpad.browser.librarian View In Hierarchy
Known subclasses: canonical.launchpad.browser.librarian.SafeStreamOrRedirectLibraryFileAliasView
Implements interfaces: zope.publisher.interfaces.browser.IBrowserPublisher
ILibraryFileAlias
.
If the file is public, it will redirect to the files http url.
Otherwise if the feature flag publicrestrictedlibrarian is set to 'on' this will allocate a token and redirect to the aliases private url.
Otherwise it will proxy the file in the appserver.
Once we no longer have any proxy code at all it should be possible to consolidate this with LibraryFileAliasView.
Note that streaming restricted files is a security concern - they show up in the launchpad.net domain rather than launchpadlibrarian.net and thus we have to take special care about their origin. SafeStreamOrRedirectLibraryFileAliasView is used when we do not trust the content, otherwise StreamOrRedirectLibraryFileAliasView. We are working to remove both of these views entirely, but some transition will be needed.
The context provides a file-like interface - it can be opened and closed and read from.
Method | getFileContents | Undocumented |
Method | __call__ | Streams the contents of the context ILibraryFileAlias . |
Method | browserDefault | Decides how to deliver the file. |
Method | publishTraverse | See IBrowserPublisher - can't traverse below a file. |
Method | _when_streaming | Hook for SafeStreamOrRedirectLibraryFileAliasView. |
ILibraryFileAlias
.
The file content is downloaded in chunks directly to a
tempfile.TemporaryFile
avoiding using large amount of memory.
The temporary file is returned to the zope publishing machinery as documented in lib/zope/publisher/httpresults.txt, after adjusting the response 'Content-Type' appropriately.
This method explicit ignores the local 'http_proxy' settings.
Only restricted file contents are streamed, finishing the traversal
chain with this view. If the context file is public return the
appropriate RedirectionView
for its HTTP url.