mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
URL hashing is now off by default - closes #418
Prior to this commit Datasette would calculate the content hash of every
database and redirect to a URL containing that hash, like so:
https://v0-27.datasette.io/fixtures => https://v0-27.datasette.io/fixtures-dd88475
This assumed that all databases were opened in immutable mode and were not
expected to change.
This will be changing as a result of #419 - so this commit takes the first step
in implementing that change by changing this default behaviour. Datasette will
now only redirect hash-free URLs under two circumstances:
* The new `hash_urls` config option is set to true (it defaults to false).
* The user passes `?_hash=1` in the URL
This commit is contained in:
parent
afe9aa3ae0
commit
6f6d0ff2b4
15 changed files with 149 additions and 70 deletions
|
|
@ -208,8 +208,14 @@ def path_with_added_args(request, args, path=None):
|
|||
|
||||
|
||||
def path_with_removed_args(request, args, path=None):
|
||||
query_string = request.query_string
|
||||
if path is None:
|
||||
path = request.path
|
||||
else:
|
||||
if "?" in path:
|
||||
bits = path.split("?", 1)
|
||||
path, query_string = bits
|
||||
# args can be a dict or a set
|
||||
path = path or request.path
|
||||
current = []
|
||||
if isinstance(args, set):
|
||||
def should_remove(key, value):
|
||||
|
|
@ -218,7 +224,7 @@ def path_with_removed_args(request, args, path=None):
|
|||
# Must match key AND value
|
||||
def should_remove(key, value):
|
||||
return args.get(key) == value
|
||||
for key, value in urllib.parse.parse_qsl(request.query_string):
|
||||
for key, value in urllib.parse.parse_qsl(query_string):
|
||||
if not should_remove(key, value):
|
||||
current.append((key, value))
|
||||
query_string = urllib.parse.urlencode(current)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue