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
|
... | ... | |
64 |
65 |
RADOS_STORAGE, RADOS_POOL_BLOCKS,
|
65 |
66 |
RADOS_POOL_MAPS, TRANSLATE_UUIDS,
|
66 |
67 |
PUBLIC_URL_SECURITY, PUBLIC_URL_ALPHABET,
|
67 |
|
COOKIE_NAME, BASE_HOST, UPDATE_MD5)
|
|
68 |
COOKIE_NAME, BASE_HOST, UPDATE_MD5, LOGIN_URL)
|
68 |
69 |
from pithos.api.resources import resources
|
69 |
70 |
from pithos.backends import connect_backend
|
70 |
71 |
from pithos.backends.base import (NotAllowedError, QuotaError, ItemNotExists,
|
... | ... | |
1125 |
1126 |
def decorator(func):
|
1126 |
1127 |
@wraps(func)
|
1127 |
1128 |
def wrapper(request, *args, **kwargs):
|
1128 |
|
request.META['HTTP_X_AUTH_TOKEN'] = get_token_from_cookie(request)
|
|
1129 |
token = get_token_from_cookie(request)
|
|
1130 |
if token is None:
|
|
1131 |
return HttpResponseRedirect('%s?next=%s' % (LOGIN_URL,
|
|
1132 |
request.path))
|
|
1133 |
request.META['HTTP_X_AUTH_TOKEN'] = token
|
1129 |
1134 |
# Get the response object
|
1130 |
1135 |
response = func(request, *args, **kwargs)
|
1131 |
|
if response.status_code == 200:
|
|
1136 |
if response.status_code in [200, 206, 304, 412, 416]:
|
1132 |
1137 |
return response
|
1133 |
1138 |
elif response.status_code == 404:
|
1134 |
1139 |
raise Http404()
|
1135 |
1140 |
elif response.status_code in [401, 403]:
|
1136 |
1141 |
return HttpResponseForbidden()
|
1137 |
1142 |
else:
|
1138 |
|
raise Exception(response)
|
|
1143 |
# unexpected response status
|
|
1144 |
raise Exception(response.status_code)
|
1139 |
1145 |
return wrapper
|
1140 |
1146 |
return decorator
|
1141 |
1147 |
|