|
|
@@ -15,7 +15,10 @@ import logging
|
|
|
from .ttypes import *
|
|
|
from thrift.Thrift import TProcessor
|
|
|
from thrift.transport import TTransport
|
|
|
+from django.utils.functional import wraps
|
|
|
+from django.utils.encoding import smart_str
|
|
|
all_structs = []
|
|
|
+LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
class Iface(object):
|
|
|
@@ -212,6 +215,28 @@ class Iface(object):
|
|
|
pass
|
|
|
|
|
|
|
|
|
+def add_xff_header(func):
|
|
|
+ def decorate(*args, **kwargs):
|
|
|
+ self = args[0]
|
|
|
+ xff = None
|
|
|
+ configuration = None
|
|
|
+ if args[1].__dict__ is not None and 'configuration' in args[1].__dict__:
|
|
|
+ configuration = args[1].__dict__['configuration']
|
|
|
+ if configuration is not None and 'HTTP-X-FORWARDED-FOR' in configuration:
|
|
|
+ xff = configuration.get('HTTP-X-FORWARDED-FOR')
|
|
|
+ try:
|
|
|
+ if hasattr(self._oprot.trans, 'TFramedTransport'):
|
|
|
+ trans_client = self._oprot.trans._TFramedTransport__trans
|
|
|
+ else:
|
|
|
+ trans_client = self._oprot.trans._TBufferedTransport__trans
|
|
|
+
|
|
|
+ trans_client.setCustomHeaders({'HTTP-X-FORWARDED-FOR': xff})
|
|
|
+ except AttributeError as e:
|
|
|
+ LOG.error('Could not set HTTP-X-FORWARDED-FOR header: %s' % smart_str(e))
|
|
|
+
|
|
|
+ return func(*args, **kwargs)
|
|
|
+ return wraps(func)(decorate)
|
|
|
+
|
|
|
class Client(Iface):
|
|
|
def __init__(self, iprot, oprot=None):
|
|
|
self._iprot = self._oprot = iprot
|
|
|
@@ -219,6 +244,7 @@ class Client(Iface):
|
|
|
self._oprot = oprot
|
|
|
self._seqid = 0
|
|
|
|
|
|
+ @add_xff_header
|
|
|
def OpenSession(self, req):
|
|
|
"""
|
|
|
Parameters:
|