Skip to content

Commit 6d6a10e

Browse files
fix(middleware): remove unused server side version check (#937)
1 parent 43354be commit 6d6a10e

2 files changed

Lines changed: 4 additions & 52 deletions

File tree

rootfs/api/middleware.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,14 @@
44
See https://docs.djangoproject.com/en/1.6/topics/http/middleware/
55
"""
66

7-
import json
8-
9-
from django.http import HttpResponse
10-
from rest_framework import status
11-
127
from api import __version__
138

149

1510
class APIVersionMiddleware(object):
1611
"""
17-
Return an error if a client request is incompatible with this REST API
18-
version, and include that REST API version with each response.
12+
Include that REST API version with each response.
1913
"""
2014

21-
def process_request(self, request):
22-
"""
23-
Return a 405 "Not Allowed" if the request's client major version
24-
doesn't match this controller's REST API major version (currently "1").
25-
"""
26-
try:
27-
client_version = request.META['HTTP_DEIS_VERSION']
28-
server_version = __version__.rsplit('.', 2)[0]
29-
if client_version != server_version:
30-
message = {
31-
'error': 'Client and server versions do not match. ' +
32-
'Client version: {} '.format(client_version) +
33-
'Server version: {}'.format(server_version)
34-
}
35-
return HttpResponse(
36-
json.dumps(message),
37-
content_type='application/json',
38-
status=status.HTTP_405_METHOD_NOT_ALLOWED
39-
)
40-
except KeyError:
41-
pass
42-
4315
def process_response(self, request, response):
4416
"""
4517
Include the controller's REST API major and minor version in

rootfs/api/tests/test_api_middleware.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,9 @@ def setUp(self):
2424

2525
def test_deis_version_header_good(self):
2626
"""
27-
Test that when the version header is sent, the request is accepted.
27+
Test that when the version header is sent.
2828
"""
29-
response = self.client.get(
30-
'/v2/apps',
31-
HTTP_DEIS_VERSION=__version__.rsplit('.', 2)[0]
32-
)
33-
self.assertEqual(response.status_code, 200, response.data)
29+
response = self.client.get('/v2/apps')
30+
self.assertEqual(response.status_code, 200)
3431
self.assertEqual(response.has_header('DEIS_API_VERSION'), True)
3532
self.assertEqual(response['DEIS_API_VERSION'], __version__.rsplit('.', 1)[0])
36-
37-
def test_deis_version_header_bad(self):
38-
"""
39-
Test that when an improper version header is sent, the request is declined.
40-
"""
41-
response = self.client.get(
42-
'/v2/apps',
43-
HTTP_DEIS_VERSION='1234.5678'
44-
)
45-
self.assertEqual(response.status_code, 405, response.content)
46-
47-
def test_deis_version_header_not_present(self):
48-
"""
49-
Test that when the version header is not present, the request is accepted.
50-
"""
51-
response = self.client.get('/v2/apps')
52-
self.assertEqual(response.status_code, 200, response.data)

0 commit comments

Comments
 (0)