mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-02 04:34:19 +00:00
use hyperlink.URL instead of custom code
This commit is contained in:
parent
24faca46a9
commit
a7c8407127
@ -10,12 +10,13 @@ from twisted.web import (
|
|||||||
from twisted.web.util import redirectTo
|
from twisted.web.util import redirectTo
|
||||||
from twisted.python.urlpath import URLPath
|
from twisted.python.urlpath import URLPath
|
||||||
|
|
||||||
|
from hyperlink import URL
|
||||||
|
|
||||||
from nevow import rend, tags as T
|
from nevow import rend, tags as T
|
||||||
from nevow.inevow import IRequest
|
from nevow.inevow import IRequest
|
||||||
from nevow.static import File as nevow_File # TODO: merge with static.File?
|
from nevow.static import File as nevow_File # TODO: merge with static.File?
|
||||||
from nevow.util import resource_filename
|
from nevow.util import resource_filename
|
||||||
|
|
||||||
|
|
||||||
import allmydata # to display import path
|
import allmydata # to display import path
|
||||||
from allmydata.version_checks import get_package_versions_string
|
from allmydata.version_checks import get_package_versions_string
|
||||||
from allmydata.util import log
|
from allmydata.util import log
|
||||||
@ -53,20 +54,25 @@ class URIHandler(resource.Resource, object):
|
|||||||
"""
|
"""
|
||||||
Historically, accessing this via "GET /uri?uri=<capabilitiy>"
|
Historically, accessing this via "GET /uri?uri=<capabilitiy>"
|
||||||
was/is a feature -- which simply redirects to the more-common
|
was/is a feature -- which simply redirects to the more-common
|
||||||
"GET /uri/<capability>". New code should use /uri/<cap>
|
"GET /uri/<capability>" with any other query args
|
||||||
|
preserved. New code should use "/uri/<cap>"
|
||||||
"""
|
"""
|
||||||
uri = get_arg(req, "uri", None)
|
uri_arg = get_arg(req, "uri", None)
|
||||||
if uri is None:
|
if uri_arg is None:
|
||||||
raise WebError("GET /uri requires uri=")
|
raise WebError("GET /uri requires uri=")
|
||||||
base = URLPath.fromRequest(req)
|
# so, using URL.from_text(req.uri) isn't going to work because
|
||||||
args = '&'.join([
|
# it seems Nevow was creating absolute URLs including
|
||||||
'{}={}'.format(name, vals[0])
|
# host/port whereas req.uri is absolute but lacks host/port
|
||||||
for name, vals in req.args.items()
|
uri = URL.from_text(req.prePathURL().decode('utf8'))
|
||||||
if name != 'uri'
|
# using ^ prePathURL() above because that includes the scheme
|
||||||
])
|
# / host / port but req.uri does not.
|
||||||
if args:
|
uri = uri.child(urllib.quote(uri_arg).decode('utf8'))
|
||||||
args = '?{}'.format(args)
|
# add back all the query args that AREN'T ?uri=
|
||||||
return redirectTo(b'{}{}'.format(base.child(urllib.quote(uri)), args), req)
|
for k, values in req.args.items():
|
||||||
|
if k != "uri":
|
||||||
|
for v in values:
|
||||||
|
uri = uri.add(k.decode('utf8'), v.decode('utf8'))
|
||||||
|
return redirectTo(uri.to_text().encode('utf8'), req)
|
||||||
|
|
||||||
def render_PUT(self, req):
|
def render_PUT(self, req):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user