mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
move tservers helper
This commit is contained in:
parent
8242f2cc9d
commit
6b585023fd
@ -18,7 +18,7 @@ logging.getLogger("PIL.Image").setLevel(logging.WARNING)
|
|||||||
logging.getLogger("PIL.PngImagePlugin").setLevel(logging.WARNING)
|
logging.getLogger("PIL.PngImagePlugin").setLevel(logging.WARNING)
|
||||||
|
|
||||||
import netlib
|
import netlib
|
||||||
from netlib import tservers as netlib_tservers
|
from ..netlib import tservers as netlib_tservers
|
||||||
from netlib.utils import http2_read_raw_frame
|
from netlib.utils import http2_read_raw_frame
|
||||||
|
|
||||||
import h2
|
import h2
|
||||||
|
@ -4,11 +4,12 @@ import codecs
|
|||||||
|
|
||||||
from hyperframe.frame import *
|
from hyperframe.frame import *
|
||||||
|
|
||||||
from netlib import tcp, http, utils, tservers
|
from netlib import tcp, http, utils
|
||||||
from netlib.tutils import raises
|
from netlib.tutils import raises
|
||||||
from netlib.exceptions import TcpDisconnect
|
from netlib.exceptions import TcpDisconnect
|
||||||
from netlib.http.http2.connections import HTTP2Protocol, TCPHandler
|
from netlib.http.http2.connections import HTTP2Protocol, TCPHandler
|
||||||
|
|
||||||
|
from ... import tservers
|
||||||
|
|
||||||
class TestTCPHandlerWrapper:
|
class TestTCPHandlerWrapper:
|
||||||
def test_wrapped(self):
|
def test_wrapped(self):
|
||||||
|
@ -10,10 +10,11 @@ import mock
|
|||||||
from OpenSSL import SSL
|
from OpenSSL import SSL
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
|
|
||||||
from netlib import tcp, certutils, tutils, tservers
|
from netlib import tcp, certutils, tutils
|
||||||
from netlib.exceptions import InvalidCertificateException, TcpReadIncomplete, TlsException, \
|
from netlib.exceptions import InvalidCertificateException, TcpReadIncomplete, TlsException, \
|
||||||
TcpTimeout, TcpDisconnect, TcpException, NetlibException
|
TcpTimeout, TcpDisconnect, TcpException, NetlibException
|
||||||
|
|
||||||
|
from . import tservers
|
||||||
|
|
||||||
class EchoHandler(tcp.BaseHandler):
|
class EchoHandler(tcp.BaseHandler):
|
||||||
sni = None
|
sni = None
|
||||||
|
@ -9,7 +9,7 @@ from netlib import tcp
|
|||||||
from netlib import tutils
|
from netlib import tutils
|
||||||
|
|
||||||
|
|
||||||
class ServerThread(threading.Thread):
|
class _ServerThread(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, server):
|
def __init__(self, server):
|
||||||
self.server = server
|
self.server = server
|
||||||
@ -22,33 +22,7 @@ class ServerThread(threading.Thread):
|
|||||||
self.server.shutdown()
|
self.server.shutdown()
|
||||||
|
|
||||||
|
|
||||||
class ServerTestBase(object):
|
class _TServer(tcp.TCPServer):
|
||||||
ssl = None
|
|
||||||
handler = None
|
|
||||||
addr = ("localhost", 0)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setup_class(cls):
|
|
||||||
cls.q = queue.Queue()
|
|
||||||
s = cls.makeserver()
|
|
||||||
cls.port = s.address.port
|
|
||||||
cls.server = ServerThread(s)
|
|
||||||
cls.server.start()
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def makeserver(cls):
|
|
||||||
return TServer(cls.ssl, cls.q, cls.handler, cls.addr)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def teardown_class(cls):
|
|
||||||
cls.server.shutdown()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def last_handler(self):
|
|
||||||
return self.server.server.last_handler
|
|
||||||
|
|
||||||
|
|
||||||
class TServer(tcp.TCPServer):
|
|
||||||
|
|
||||||
def __init__(self, ssl, q, handler_klass, addr):
|
def __init__(self, ssl, q, handler_klass, addr):
|
||||||
"""
|
"""
|
||||||
@ -107,3 +81,29 @@ class TServer(tcp.TCPServer):
|
|||||||
s = StringIO()
|
s = StringIO()
|
||||||
tcp.TCPServer.handle_error(self, connection, client_address, s)
|
tcp.TCPServer.handle_error(self, connection, client_address, s)
|
||||||
self.q.put(s.getvalue())
|
self.q.put(s.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
class ServerTestBase(object):
|
||||||
|
ssl = None
|
||||||
|
handler = None
|
||||||
|
addr = ("localhost", 0)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setup_class(cls):
|
||||||
|
cls.q = queue.Queue()
|
||||||
|
s = cls.makeserver()
|
||||||
|
cls.port = s.address.port
|
||||||
|
cls.server = _ServerThread(s)
|
||||||
|
cls.server.start()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def makeserver(cls):
|
||||||
|
return _TServer(cls.ssl, cls.q, cls.handler, cls.addr)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def teardown_class(cls):
|
||||||
|
cls.server.shutdown()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_handler(self):
|
||||||
|
return self.server.server.last_handler
|
@ -2,12 +2,12 @@ import os
|
|||||||
|
|
||||||
from netlib.http.http1 import read_response, read_request
|
from netlib.http.http1 import read_response, read_request
|
||||||
|
|
||||||
from netlib import tcp, websockets, http, tutils, tservers
|
from netlib import tcp, websockets, http, tutils
|
||||||
from netlib.http import status_codes
|
from netlib.http import status_codes
|
||||||
from netlib.tutils import treq
|
from netlib.tutils import treq
|
||||||
|
|
||||||
from netlib.exceptions import *
|
from netlib.exceptions import *
|
||||||
|
|
||||||
|
from .. import tservers
|
||||||
|
|
||||||
class WebSocketsEchoHandler(tcp.BaseHandler):
|
class WebSocketsEchoHandler(tcp.BaseHandler):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user