diff options
author | Daniel Schadt <kingdread@gmx.de> | 2022-12-03 23:30:31 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2022-12-03 23:30:31 +0100 |
commit | a95a9768135bcaaa856a7cca98409a49250c96fa (patch) | |
tree | 0675487e6181eed5264bce2db737f3f947963312 | |
parent | 8e8dd9f8a786bc4036dfbe0b70f03724801b8a8f (diff) | |
download | fietsboek-a95a9768135bcaaa856a7cca98409a49250c96fa.tar.gz fietsboek-a95a9768135bcaaa856a7cca98409a49250c96fa.tar.bz2 fietsboek-a95a9768135bcaaa856a7cca98409a49250c96fa.zip |
serve gzip compressed GPX data if possible
This way, we not only save the decompression time, we can also save
bandwidth! We *might* even consider using brotli, which seems to be
widely supported and has even better compression ratios, but brotli
compression of full efficiency is also slow.
Ideally, we'd save a "fast compressed" version of the GPX file on
upload, and then have a slower background-queue re-compress them with
higher settings. That however should probably wait till we move the GPX
data out of the database(?!), then we can even serve the data straight
with a FileResponse.
-rw-r--r-- | fietsboek/views/detail.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py index 38dc31f..a135916 100644 --- a/fietsboek/views/detail.py +++ b/fietsboek/views/detail.py @@ -59,7 +59,13 @@ def gpx(request): :rtype: pyramid.response.Response """ track = request.context - response = Response(track.gpx_data, content_type="application/gpx+xml") + # We can be nice to the client if they support it, and deliver the gzipped + # data straight. This saves decompression time on the server and saves a + # lot of bandwidth. + if 'gzip' in request.accept_encoding: + response = Response(track.gpx, content_type="application/gpx+xml", content_encoding="gzip") + else: + response = Response(track.gpx_data, content_type="application/gpx+xml") response.md5_etag() return response |