Browse Source

web/jump/views.py: preserve GET variables when redirecting

pull/1/head
Hidden Z 14 years ago
parent
commit
e0b9ad980c
  1. 12
      web/jump/views.py

12
web/jump/views.py

@ -1,3 +1,5 @@
import re
from django.shortcuts import redirect from django.shortcuts import redirect
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.http import HttpResponse from django.http import HttpResponse
@ -5,10 +7,10 @@ from django.http import HttpResponse
from web.postkey.models import i2phost from web.postkey.models import i2phost
from web.lib.validation import validate_hostname from web.lib.validation import validate_hostname
def jumper(request, data): def jumper(request, host):
"""Actually do jumps.""" """Actually do jumps."""
try: try:
hostname = validate_hostname(data) hostname = validate_hostname(host)
except ValidationError, e: except ValidationError, e:
return redirect('/jump/error/') return redirect('/jump/error/')
try: try:
@ -16,6 +18,12 @@ def jumper(request, data):
except i2phost.DoesNotExist: except i2phost.DoesNotExist:
return redirect('/jump/unknown/') return redirect('/jump/unknown/')
url = 'http://' + hostname + '/?i2paddresshelper=' + key url = 'http://' + hostname + '/?i2paddresshelper=' + key
# get params from requst string, e.g. from 'example.i2p/smth/1?a=b&c=d' get 'smth/1?a=b&c=d'
pattern = host + r'/(.+)'
m = re.search(pattern, request.get_full_path())
if m:
params = m.group(1)
url += '/' + params
return redirect(url, permanent=True) return redirect(url, permanent=True)
def error(request): def error(request):

Loading…
Cancel
Save