Skip to content

Commit 9ba8dc2

Browse files
committed
Merge pull request #3706 from mboersma/middleware-cleanup
ref(controller): add docstrings to middleware module
2 parents 0c15954 + 8e25040 commit 9ba8dc2

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

controller/api/middleware.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
HTTP middleware for the Deis REST API.
3+
4+
See https://docs.djangoproject.com/en/1.6/topics/http/middleware/
5+
"""
6+
17
import json
28

39
from django.http import HttpResponse
@@ -6,18 +12,25 @@
612
from api import __version__
713

814

9-
class APIVersionMiddleware:
15+
class APIVersionMiddleware(object):
16+
"""
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.
19+
"""
1020

1121
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+
"""
1226
try:
13-
# server and client version must match the major release point
1427
client_version = request.META['HTTP_X_DEIS_VERSION']
1528
server_version = __version__.rsplit('.', 2)[0]
1629
if client_version != server_version:
1730
message = {
1831
'error': 'Client and server versions do not match. ' +
19-
'Client version: {} '.format(client_version) +
20-
'Server version: {}'.format(server_version)
32+
'Client version: {} '.format(client_version) +
33+
'Server version: {}'.format(server_version)
2134
}
2235
return HttpResponse(
2336
json.dumps(message),
@@ -28,6 +41,10 @@ def process_request(self, request):
2841
pass
2942

3043
def process_response(self, request, response):
44+
"""
45+
Include the controller's REST API major and minor version in
46+
a response header.
47+
"""
3148
# clients shouldn't care about the patch release
3249
response['X_DEIS_API_VERSION'] = __version__.rsplit('.', 1)[0]
3350
return response

0 commit comments

Comments
 (0)