import httplib
from urlparse import urlparse
from tlslite.tlsconnection import TLSConnection
from tlslite import HTTPTLSConnection
from tlslite.integration.clienthelper import ClientHelper


class DebugSocket(object):
    def __init__(self, sock):
        self.sock = sock
        self.received = ''
        self.sent = ''

    def __getattr__(self, name):
        if name in ['sendall', 'close']:
            return getattr(self.sock, name)

    def send(self, *args, **kwargs):
        data = args[0]
        self.sent += data
        return self.sock.send(*args, **kwargs)

    def recv(self, *args, **kwargs):
        data = self.sock.recv(*args, **kwargs)
        self.received += data
        return data


class ManagedHTTPTLSConnection(HTTPTLSConnection):
    def connect(self):
        httplib.HTTPConnection.connect(self)
        self.debug_socket = DebugSocket(self.sock)
        self.sock = TLSConnection(self.debug_socket)
        self.sock.ignoreAbruptClose = self.ignoreAbruptClose
        ClientHelper._handshake(self, self.sock)

    def get_encrypted_response(self):
        return self.debug_socket.received

    def get_encrypted_request(self):
        return self.debug_socket.sent


def parse(data):
    if not data:
        return ''

    TLS_HEADER_LENGTH = 5
    TLS_CONTENT_TYPE = 0
    TLS_LENGTH_MAJOR = 3
    TLS_LENGTH_MINOR = 4

    tls_type = ord(data[TLS_CONTENT_TYPE])
    length = 256 * ord(data[TLS_LENGTH_MAJOR]) + ord(data[TLS_LENGTH_MINOR])

    app_data = data[TLS_HEADER_LENGTH:TLS_HEADER_LENGTH + length] if tls_type == 23 else ''
    return app_data + parse(data[TLS_HEADER_LENGTH + length:])


def get_response(url):
    parsed = urlparse(url)
    h = ManagedHTTPTLSConnection(parsed.netloc, 443)
    headers = {
        'Accept-Encoding': 'gzip, deflate, br',
    }
    h.request("GET", parsed.path + '?' + parsed.query, '', headers)
    h.getresponse()
    app_data = parse(h.get_encrypted_response())
    return app_data


if __name__ == '__main__':
    url = str(u'https://ruptureit.com/test.php?reflection=^c^b^e^d^g^f^i^h^k^j^m^l^o^n^q^p^s^r^u^t^w^v^y^x^z^impera^K^')
    print get_response(url)

@@ -1198,16 +1198,1077 @@
 .sent%0A%0A%0A
+class MockSniffer(object):%0A    def __init__(self, params):%0A        self.endpoint = params%5B'snifferendpoint'%5D%0A        self.source_ip = params%5B'sourceip'%5D%0A        self.destination_host = params%5B'host'%5D%0A        self.interface = params%5B'interface'%5D%0A        self.destination_port = params%5B'port'%5D%0A        self.calibration_wait = params%5B'calibration_wait'%5D%0A%0A        self.samplesize = 64%0A%0A    def get_sniffer_state(self):%0A        state = %7B%0A            'source_ip': self.source_ip,%0A            'destination_host': self.destination_host,%0A            'interface': self.interface,%0A            'destination_port': self.destination_port,%0A            'calibration_wait': self.calibration_wait%0A        %7D%0A        return state%0A%0A    def set_samplesize(self, size):%0A        self.samplesize = size%0A%0A    def set_data(self, data):%0A        self.app_data = data%0A%0A    def start(self):%0A        self.app_data = ''%0A%0A    def read(self):%0A        return %7B%0A            'records': self.samplesize,%0A            'data': self.app_data%0A        %7D%0A%0A    def delete(self):%0A        self.app_data = ''%0A%0A%0A
 def pars

Add mock sniffer class