2019-12-02 06:46:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
proxy.py
|
|
|
|
~~~~~~~~
|
|
|
|
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
|
|
|
|
Network monitoring, controls & Application development, testing, debugging.
|
|
|
|
|
|
|
|
:copyright: (c) 2013-present by Abhinav Singh and contributors.
|
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
2020-10-14 05:21:56 +00:00
|
|
|
import argparse
|
2019-12-02 06:46:00 +00:00
|
|
|
from typing import List, Tuple
|
2020-02-01 16:51:25 +00:00
|
|
|
from uuid import UUID
|
2019-12-02 06:46:00 +00:00
|
|
|
from ..websocket import WebsocketFrame
|
|
|
|
from ..parser import HttpParser
|
|
|
|
|
|
|
|
from ...core.connection import TcpClientConnection
|
|
|
|
from ...core.event import EventQueue
|
|
|
|
|
|
|
|
|
|
|
|
class HttpWebServerBasePlugin(ABC):
|
|
|
|
"""Web Server Plugin for routing of requests."""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2020-02-01 16:51:25 +00:00
|
|
|
uid: UUID,
|
2020-10-14 05:21:56 +00:00
|
|
|
flags: argparse.Namespace,
|
2019-12-02 06:46:00 +00:00
|
|
|
client: TcpClientConnection,
|
|
|
|
event_queue: EventQueue):
|
|
|
|
self.uid = uid
|
|
|
|
self.flags = flags
|
|
|
|
self.client = client
|
|
|
|
self.event_queue = event_queue
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def routes(self) -> List[Tuple[int, str]]:
|
|
|
|
"""Return List(protocol, path) that this plugin handles."""
|
|
|
|
raise NotImplementedError() # pragma: no cover
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def handle_request(self, request: HttpParser) -> None:
|
|
|
|
"""Handle the request and serve response."""
|
|
|
|
raise NotImplementedError() # pragma: no cover
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def on_websocket_open(self) -> None:
|
|
|
|
"""Called when websocket handshake has finished."""
|
|
|
|
raise NotImplementedError() # pragma: no cover
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def on_websocket_message(self, frame: WebsocketFrame) -> None:
|
|
|
|
"""Handle websocket frame."""
|
|
|
|
raise NotImplementedError() # pragma: no cover
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def on_websocket_close(self) -> None:
|
|
|
|
"""Called when websocket connection has been closed."""
|
|
|
|
raise NotImplementedError() # pragma: no cover
|