Fix redirect locations
When the application is not mounted at the root of the (virtual) host, the Location header of HTTP redirect responses need to take this into account. I thought that the `HTTPSeeOther` exception handled this, but it does not, so the path needs to be explicitly constructed with `milla.Request.create_href`.master
parent
2db6a22376
commit
f8cbf8b29c
|
@ -153,7 +153,9 @@ class ZoneController(BaseController):
|
|||
setattr(zone, k, v)
|
||||
self.session.commit()
|
||||
if request.want in 'xhtml':
|
||||
raise milla.HTTPSeeOther(location='/zones/{}'.format(zone.name))
|
||||
raise milla.HTTPSeeOther(
|
||||
location=request.create_href('/zones/{}'.format(zone.name))
|
||||
)
|
||||
response.status_int = 204
|
||||
return response
|
||||
|
||||
|
@ -182,7 +184,9 @@ class ZoneController(BaseController):
|
|||
self.session.add(record)
|
||||
self.session.commit()
|
||||
if request.want in ('html', 'xhtml'):
|
||||
raise milla.HTTPSeeOther(location='/zones/{}'.format(zone_name))
|
||||
raise milla.HTTPSeeOther(
|
||||
location=request.create_href('/zones/{}'.format(zone_name))
|
||||
)
|
||||
else:
|
||||
response.status_int = 201
|
||||
response.location = request.create_href_full(
|
||||
|
@ -197,7 +201,7 @@ class ZoneController(BaseController):
|
|||
self.session.delete(zone)
|
||||
self.session.commit()
|
||||
if request.want in ('html', 'xhtml'):
|
||||
raise milla.HTTPSeeOther(location='/zones/')
|
||||
raise milla.HTTPSeeOther(location=request.create_href('/zones/'))
|
||||
response.status_int = 204
|
||||
return response
|
||||
|
||||
|
@ -245,7 +249,9 @@ class RecordController(BaseController):
|
|||
setattr(record, k, v)
|
||||
self.session.commit()
|
||||
if request.want in ('html', 'xhtml'):
|
||||
raise milla.HTTPSeeOther(location='/zones/{}'.format(record.zone))
|
||||
raise milla.HTTPSeeOther(
|
||||
location=request.create_href('/zones/{}'.format(record.zone))
|
||||
)
|
||||
response.status_int = 201
|
||||
return response
|
||||
|
||||
|
@ -256,6 +262,8 @@ class RecordController(BaseController):
|
|||
self.session.delete(record)
|
||||
self.session.commit()
|
||||
if request.want in ('html', 'xhtml'):
|
||||
raise milla.HTTPSeeOther(location='/zones/{}'.format(record.zone))
|
||||
raise milla.HTTPSeeOther(
|
||||
location=request.create_href('/zones/{}'.format(record.zone))
|
||||
)
|
||||
response.status_int = 204
|
||||
return response
|
||||
|
|
Reference in New Issue