aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-12-14 19:35:20 +0100
committerDaniel Schadt <kingdread@gmx.de>2022-12-14 19:37:20 +0100
commitd5830f4000bf8f96d821fd3e93f04898af03132e (patch)
treecb4e2d8a9a76d72a60bbe915856278f5678f9ed8
parent2216398346b49a13ec217a924c583b05de47e889 (diff)
downloadfietsboek-d5830f4000bf8f96d821fd3e93f04898af03132e.tar.gz
fietsboek-d5830f4000bf8f96d821fd3e93f04898af03132e.tar.bz2
fietsboek-d5830f4000bf8f96d821fd3e93f04898af03132e.zip
change deprecated way of Accept-Encoding header
-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