Support compressed files in send_file() (Fixes #93)
This commit is contained in:
20
examples/static/gzstatic.py
Normal file
20
examples/static/gzstatic.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from microdot import Microdot, send_file
|
||||
|
||||
app = Microdot()
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index(request):
|
||||
return send_file('gzstatic/index.html', compressed=True,
|
||||
file_extension='.gz')
|
||||
|
||||
|
||||
@app.route('/static/<path:path>')
|
||||
def static(request, path):
|
||||
if '..' in path:
|
||||
# directory traversal is not allowed
|
||||
return 'Not found', 404
|
||||
return send_file('gzstatic/' + path, compressed=True, file_extension='.gz')
|
||||
|
||||
|
||||
app.run(debug=True)
|
||||
BIN
examples/static/gzstatic/index.html.gz
Normal file
BIN
examples/static/gzstatic/index.html.gz
Normal file
Binary file not shown.
BIN
examples/static/gzstatic/logo.png.gz
Normal file
BIN
examples/static/gzstatic/logo.png.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user