aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fietsboek/views/detail.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py
index e0ca113..485bad3 100644
--- a/fietsboek/views/detail.py
+++ b/fietsboek/views/detail.py
@@ -4,7 +4,7 @@ import datetime
from pyramid.view import view_config
from pyramid.response import Response, FileResponse
from pyramid.i18n import TranslationString as _
-from pyramid.httpexceptions import HTTPFound, HTTPNotFound
+from pyramid.httpexceptions import HTTPFound, HTTPNotFound, HTTPNotAcceptable
from sqlalchemy import select
@@ -63,10 +63,18 @@ def gpx(request):
# 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")
+ accepted = request.accept_encoding.acceptable_offers(["gzip", "identity"])
+ for encoding, _qvalue in accepted:
+ if encoding == "gzip":
+ response = Response(
+ track.gpx, content_type="application/gpx+xml", content_encoding="gzip"
+ )
+ break
+ if encoding == "identity":
+ response = Response(track.gpx_data, content_type="application/gpx+xml")
+ break
else:
- response = Response(track.gpx_data, content_type="application/gpx+xml")
+ return HTTPNotAcceptable("No data with acceptable encoding found")
response.md5_etag()
return response