fix the path given by the set-cookie header

This commit is contained in:
Damien Churchill 2011-05-03 19:05:04 +01:00
parent 138b8ae314
commit d362a6ceba
2 changed files with 61 additions and 58 deletions

View File

@ -135,9 +135,8 @@ class Auth(JSONComponent):
expires, expires_str = make_expires(config["session_timeout"]) expires, expires_str = make_expires(config["session_timeout"])
checksum = str(make_checksum(session_id)) checksum = str(make_checksum(session_id))
base = str(component.get("Web").get_config()["base"])
request.addCookie('_session_id', session_id + checksum, request.addCookie('_session_id', session_id + checksum,
path=base+"json", expires=expires_str) path=request.base+"json", expires=expires_str)
log.debug("Creating session for %s", login) log.debug("Creating session for %s", login)
config = component.get("DelugeWeb").config config = component.get("DelugeWeb").config
@ -233,9 +232,8 @@ class Auth(JSONComponent):
session["expires"] = expires session["expires"] = expires
_session_id = request.getCookie("_session_id") _session_id = request.getCookie("_session_id")
base = str(component.get("Web").get_config()["base"])
request.addCookie('_session_id', _session_id, request.addCookie('_session_id', _session_id,
path=base+"json", expires=expires_str) path=request.base+"json", expires=expires_str)
if method: if method:
if not hasattr(method, "_json_export"): if not hasattr(method, "_json_export"):

View File

@ -518,13 +518,31 @@ class TopLevel(resource.Resource):
self.__scripts.remove(script) self.__scripts.remove(script)
self.__debug_scripts.remove(script) self.__debug_scripts.remove(script)
def getChild(self, path, request): def getChild(self, path, request):
if path == "": if path == "":
return self return self
else: else:
return resource.Resource.getChild(self, path, request) return resource.Resource.getChild(self, path, request)
def getChildWithDefault(self, path, request):
# Calculate the request base
header = request.getHeader('x-deluge-base')
base = header if header else component.get("DelugeWeb").base
# validate the base parameter
if not base:
base = '/'
if base[0] != '/':
base = '/' + base
if base[-1] != '/':
base += '/'
request.base = base.encode('idna')
return resource.Resource.getChildWithDefault(self, path, request)
def render(self, request): def render(self, request):
debug = False debug = False
if 'debug' in request.args: if 'debug' in request.args:
@ -555,25 +573,12 @@ class TopLevel(resource.Resource):
template = Template(filename=rpath("index.html")) template = Template(filename=rpath("index.html"))
request.setHeader("content-type", "text/html; charset=utf-8") request.setHeader("content-type", "text/html; charset=utf-8")
header = request.getHeader('x-deluge-base')
base = header if header else component.get("DelugeWeb").base
# validate the base parameter
if not base:
base = '/'
if base[0] != '/':
base = '/' + base
if base[-1] != '/':
base += '/'
web_config = component.get("Web").get_config() web_config = component.get("Web").get_config()
web_config["base"] = base web_config["base"] = request.base
config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS]) config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS])
js_config = common.json.dumps(config) js_config = common.json.dumps(config)
return template.render(scripts=scripts, stylesheets=self.stylesheets, return template.render(scripts=scripts, stylesheets=self.stylesheets,
debug=debug, base=base, js_config=js_config) debug=debug, base=request.base, js_config=js_config)
class ServerContextFactory: class ServerContextFactory: