-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmiddleware.py
More file actions
25 lines (20 loc) · 804 Bytes
/
middleware.py
File metadata and controls
25 lines (20 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
from django.http import HttpResponse
from deis import __version__
class VersionMiddleware:
def process_request(self, request):
# server and client version must match "x.y"
server_version = __version__.rsplit('.', 1)[0]
try:
if request.META['HTTP_X_DEIS_VERSION'] != server_version:
message = {
'error': 'Client and server versions do not match.\n' +
'Client version: {}\n'.format(server_version) +
'Server version: {}'.format(request.META['HTTP_X_DEIS_VERSION'])
}
return HttpResponse(
json.dumps(message),
content_type='application/json'
)
except KeyError:
pass