-
Notifications
You must be signed in to change notification settings - Fork 9
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
Serve static files #346
Open
johanjanssens
wants to merge
14
commits into
master
Choose a base branch
from
feature/345-file
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Serve static files #346
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This allows pages to be to redirect any url, anywhere, even when not in a page context.
identifiers by a custom scheme and rename 'pages' scheme to 'page'
The callback is defined is as follows: 'function($route, $generate = false)' - $route: a ComPagesDispatcherRouteRouteInterface object - $generate: are we generating a url or resolving (default false) Callbacks are both supported for static and dynamic routes, in case of a dynamic route the callback is called only if the route could be succesfully resolved.
Example: '/path/to/page' => [ 'generate' => function($route) { return true; }, 'resolve' => function($route) { return true; } ],
A file route is absolute if the path of the route is a fully qualified file path
Add support for the 'force-download' query parameter. If specified the file will be downloaded instead of allowing the browser to preview the file if it can do so. For example: 'files/[:name]' => '/files/documents/[:name].pdf?force-download'
The `transport`query parameter allows to define which transport. At the moment two additional transports are supported: `stream` and `sendfile
ercanozkaya
approved these changes
May 18, 2020
cache query parameter The cache query parameter allows to define the max-age in seconds.
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a static file router and downloader. The file router offers support for both pattern and callback based routing.
Static file routing is available globally, file downloads can be setup outside of the context of Pages for any url on your Joomla site.
Adding routes
Routes are defined in the configuration through the new
files
config option. For example:If the route target is not a fully qualified file path it is considered a relative path starting from the Joomla root directory.
Global configuration
You do not need to setup a
/joomlatools-pages
folder to be able to define file routes. If you just want to use this feature add aconfiguration-pages.php
to your Joomla root, and defines your file routes there, they will just work.Force downloading
By default browsers will preview files they recognise, for example, images, pdf files and specific video formats. If you want to force the browser to download the file instead you can either add
force-download
to the url or to the route.Using URL
>> http://example.com/documents/foo?force-download
Using route
>> 'documents/[:name]' => '/images/files/documents/[:name].pdf?force-download'
Different transports
The downloader offers support for two additional transports:
stream
andsendfile
. The transport can be defined using thetransport
query parameter in the route target.>> 'documents/[:name]' => '/images/files/documents/[:name].pdf?transport=[name]'
Stream
>> 'documents/[:name]' => '/images/files/documents/[:name].pdf?transport=stream'
Streaming is a data transfer mechanism in version HTTP 1.1 in which a web server serves content in a series of chunks.
Pages uses Byte Serving to stream files. This mechanism is the process of sending only a portion of the data from a server to a client. Range-serving uses the Range HTTP request header and the Accept-Ranges and Content-Range HTTP response headers.
Clients which request range-serving might do so in cases in which a large file has been only partially delivered and a limited portion of the file is needed in a particular range. Range Serving is therefore a method of bandwidth optimisation.
Tip: Use streaming to send larger files faster, for example to download large pdf files and allow to view the first page before the file has completely downloaded, or to stream video or audio files.
Sendfile
>> 'documents/[:name]' => '/images/files/documents/[:name].pdf?transport=sendfile'
Sendfile allows for internal redirection to a location determined by a header returned from a backend. This allows to handle authentication, logging or whatever else you please in your backend and then have the server serve the contents from redirected location to the client, thus freeing up the backend to handle other requests.
Following servers are supported:
Configure caching
You can configure the cache lifetime through the
cache
query parameter in the route target. It will set themax-age
value for the Cache-Control header when the response is send.The cache parameters offers support for English textual relative datetime formats as supported by strtotime, for example:
See also: joomlatools/joomlatools-framework#373
For example, set the cache lifetime to 1day
>> 'documents/[:name]' => '/images/files/documents/[:name].pdf?cache=1day'