Revision a421e0b9 snf-pithos-app/pithos/api/util.py
b/snf-pithos-app/pithos/api/util.py | ||
---|---|---|
35 | 35 |
from datetime import datetime |
36 | 36 |
from urllib import quote, unquote |
37 | 37 |
|
38 |
from django.http import HttpResponse, Http404, HttpResponseForbidden |
|
38 |
from django.http import (HttpResponse, HttpResponseRedirect, Http404, |
|
39 |
HttpResponseForbidden) |
|
39 | 40 |
from django.template.loader import render_to_string |
40 | 41 |
from django.utils import simplejson as json |
41 | 42 |
from django.utils.http import http_date, parse_etags |
... | ... | |
63 | 64 |
RADOS_POOL_MAPS, TRANSLATE_UUIDS, |
64 | 65 |
PUBLIC_URL_SECURITY, |
65 | 66 |
PUBLIC_URL_ALPHABET, |
66 |
COOKIE_NAME, BASE_HOST) |
|
67 |
COOKIE_NAME, BASE_HOST, LOGIN_URL)
|
|
67 | 68 |
from pithos.api.resources import resources |
68 | 69 |
from pithos.backends.base import (NotAllowedError, QuotaError, ItemNotExists, |
69 | 70 |
VersionNotExists) |
... | ... | |
1113 | 1114 |
def decorator(func): |
1114 | 1115 |
@wraps(func) |
1115 | 1116 |
def wrapper(request, *args, **kwargs): |
1116 |
request.META['HTTP_X_AUTH_TOKEN'] = get_token_from_cookie(request) |
|
1117 |
token = get_token_from_cookie(request) |
|
1118 |
if token is None: |
|
1119 |
return HttpResponseRedirect('%s?next=%s' % (LOGIN_URL, |
|
1120 |
request.path)) |
|
1121 |
request.META['HTTP_X_AUTH_TOKEN'] = token |
|
1117 | 1122 |
# Get the response object |
1118 | 1123 |
response = func(request, *args, **kwargs) |
1119 |
if response.status_code == 200:
|
|
1124 |
if response.status_code in [200, 206, 304, 412, 416]:
|
|
1120 | 1125 |
return response |
1121 | 1126 |
elif response.status_code == 404: |
1122 | 1127 |
raise Http404() |
1123 | 1128 |
elif response.status_code in [401, 403]: |
1124 | 1129 |
return HttpResponseForbidden() |
1125 | 1130 |
else: |
1126 |
raise Exception(response) |
|
1131 |
# unexpected response status |
|
1132 |
raise Exception(response.status_code) |
|
1127 | 1133 |
return wrapper |
1128 | 1134 |
return decorator |
Also available in: Unified diff