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)
|
setattr(zone, k, v)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
if request.want in 'xhtml':
|
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
|
response.status_int = 204
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -182,7 +184,9 @@ class ZoneController(BaseController):
|
||||||
self.session.add(record)
|
self.session.add(record)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
if request.want in ('html', 'xhtml'):
|
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:
|
else:
|
||||||
response.status_int = 201
|
response.status_int = 201
|
||||||
response.location = request.create_href_full(
|
response.location = request.create_href_full(
|
||||||
|
@ -197,7 +201,7 @@ class ZoneController(BaseController):
|
||||||
self.session.delete(zone)
|
self.session.delete(zone)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
if request.want in ('html', 'xhtml'):
|
if request.want in ('html', 'xhtml'):
|
||||||
raise milla.HTTPSeeOther(location='/zones/')
|
raise milla.HTTPSeeOther(location=request.create_href('/zones/'))
|
||||||
response.status_int = 204
|
response.status_int = 204
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -245,7 +249,9 @@ class RecordController(BaseController):
|
||||||
setattr(record, k, v)
|
setattr(record, k, v)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
if request.want in ('html', 'xhtml'):
|
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
|
response.status_int = 201
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -256,6 +262,8 @@ class RecordController(BaseController):
|
||||||
self.session.delete(record)
|
self.session.delete(record)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
if request.want in ('html', 'xhtml'):
|
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
|
response.status_int = 204
|
||||||
return response
|
return response
|
||||||
|
|
Reference in New Issue