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.\n' +
                    'Client version: {}\n'.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

@@ -516,18 +516,17 @@
 t match.
-%5Cn
+ 
 ' +%0A    
@@ -564,10 +564,9 @@
 : %7B%7D
-%5Cn
+ 
 '.fo

remove newline characters from response