-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmiddleware.py
More file actions
28 lines (23 loc) · 930 Bytes
/
middleware.py
File metadata and controls
28 lines (23 loc) · 930 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
26
27
28
import json
from django.http import HttpResponse
from rest_framework import status
from deis import __version__
class VersionMiddleware:
def process_request(self, request):
try:
# server and client version must match "x.y"
client_version = request.META['HTTP_X_DEIS_VERSION']
server_version = __version__.rsplit('.', 1)[0]
if client_version != server_version:
message = {
'error': 'Client and server versions do not match. ' +
'Client version: {} '.format(client_version) +
'Server version: {}'.format(server_version)
}
return HttpResponse(
json.dumps(message),
content_type='application/json',
status=status.HTTP_405_METHOD_NOT_ALLOWED
)
except KeyError:
pass