1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-02-09 05:14:22 +00:00

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

This commit is contained in:
Hidden Z 2010-10-25 17:30:42 +00:00
parent 19023be247
commit e0b9ad980c

View File

@ -1,3 +1,5 @@
import re
from django.shortcuts import redirect
from django.core.exceptions import ValidationError
from django.http import HttpResponse
@ -5,10 +7,10 @@ from django.http import HttpResponse
from web.postkey.models import i2phost
from web.lib.validation import validate_hostname
def jumper(request, data):
def jumper(request, host):
"""Actually do jumps."""
try:
hostname = validate_hostname(data)
hostname = validate_hostname(host)
except ValidationError, e:
return redirect('/jump/error/')
try:
@ -16,6 +18,12 @@ def jumper(request, data):
except i2phost.DoesNotExist:
return redirect('/jump/unknown/')
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)
def error(request):