From fad224805c207c871cde0a394ee5eae7fb9c3750 Mon Sep 17 00:00:00 2001 From: Leo Trubach Date: Mon, 2 Dec 2019 00:12:36 +0600 Subject: [PATCH 1/2] Support for another types of auth tokens (i.e. apikey) --- rest_framework_proxy/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rest_framework_proxy/views.py b/rest_framework_proxy/views.py index 0fec330..92e60b6 100644 --- a/rest_framework_proxy/views.py +++ b/rest_framework_proxy/views.py @@ -90,10 +90,12 @@ def get_headers(self, request): auth_token = '%s:%s' % (username, password) auth_token = base64.b64encode(auth_token.encode('utf-8')).decode() headers['Authorization'] = 'Basic %s' % auth_token - else: - auth_token = self.proxy_settings.AUTH.get('token') - if auth_token: - headers['Authorization'] = auth_token + return headers + auth_token = self.proxy_settings.AUTH.get('token') + if auth_token: + headers['Authorization'] = auth_token + return headers + headers.update(self.proxy_settings.AUTH) return headers def get_verify_ssl(self, request): From a21273836a07b1d6aca973a4729d20c2a3deff60 Mon Sep 17 00:00:00 2001 From: Leo Trubach Date: Wed, 4 Mar 2020 15:33:12 +0600 Subject: [PATCH 2/2] Django 3 compatibility --- requirements/requirements-development.txt | 1 + rest_framework_proxy/views.py | 9 +++++++-- setup.py | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/requirements/requirements-development.txt b/requirements/requirements-development.txt index b271ddb..ca6a805 100644 --- a/requirements/requirements-development.txt +++ b/requirements/requirements-development.txt @@ -1,3 +1,4 @@ django>=1.8 djangorestframework>=3.1.0 requests>=1.1.0 +six diff --git a/rest_framework_proxy/views.py b/rest_framework_proxy/views.py index 92e60b6..43cc7b3 100644 --- a/rest_framework_proxy/views.py +++ b/rest_framework_proxy/views.py @@ -2,8 +2,13 @@ import json import requests -from django.utils import six -from django.utils.six import BytesIO as StringIO +try: + from django.utils import six + from django.utils.six import BytesIO as StringIO +except ImportError: + import six + from six import BytesIO as StringIO + from requests.exceptions import ConnectionError, SSLError, Timeout from requests import sessions from django.http import HttpResponse diff --git a/setup.py b/setup.py index e35459c..b53ee02 100755 --- a/setup.py +++ b/setup.py @@ -17,7 +17,8 @@ install_requires = [ 'django>=1.8', 'djangorestframework>=3.1.0', - 'requests>=1.1.0' + 'requests>=1.1.0', + 'six' ] classifiers = [ 'Environment :: Web Environment',