github.com/tmlbl/deis@v1.0.2/controller/api/middleware.py (about)

     1  import json
     2  
     3  from django.http import HttpResponse
     4  from rest_framework import status
     5  
     6  from deis import __version__
     7  
     8  
     9  class VersionMiddleware:
    10  
    11      def process_request(self, request):
    12          try:
    13              # server and client version must match "x.y"
    14              client_version = request.META['HTTP_X_DEIS_VERSION']
    15              server_version = __version__.rsplit('.', 1)[0]
    16              if client_version != server_version:
    17                  message = {
    18                      'error': 'Client and server versions do not match. ' +
    19                      'Client version: {} '.format(client_version) +
    20                      'Server version: {}'.format(server_version)
    21                  }
    22                  return HttpResponse(
    23                      json.dumps(message),
    24                      content_type='application/json',
    25                      status=status.HTTP_405_METHOD_NOT_ALLOWED
    26                  )
    27          except KeyError:
    28              pass