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.
|
2021-11-16 23:34:29 +00:00
|
|
|
|
|
|
|
.. spelling::
|
|
|
|
|
|
|
|
conn
|
2019-12-02 06:46:00 +00:00
|
|
|
"""
|
2021-12-22 03:50:06 +00:00
|
|
|
from typing import TYPE_CHECKING, Any
|
2021-12-21 23:54:31 +00:00
|
|
|
|
2019-12-02 06:46:00 +00:00
|
|
|
from .base import HttpProtocolException
|
2021-11-14 21:47:12 +00:00
|
|
|
|
2021-12-24 19:00:40 +00:00
|
|
|
from ..responses import BAD_GATEWAY_RESPONSE_PKT
|
2019-12-02 06:46:00 +00:00
|
|
|
|
2022-01-14 09:43:14 +00:00
|
|
|
if TYPE_CHECKING: # pragma: no cover
|
2021-12-21 23:54:31 +00:00
|
|
|
from ..parser import HttpParser
|
|
|
|
|
2019-12-02 06:46:00 +00:00
|
|
|
|
|
|
|
class ProxyConnectionFailed(HttpProtocolException):
|
2021-11-16 23:34:29 +00:00
|
|
|
"""Exception raised when ``HttpProxyPlugin`` is unable to establish connection to upstream server."""
|
2019-12-02 06:46:00 +00:00
|
|
|
|
2021-12-22 03:50:06 +00:00
|
|
|
def __init__(self, host: str, port: int, reason: str, **kwargs: Any):
|
2019-12-02 06:46:00 +00:00
|
|
|
self.host: str = host
|
|
|
|
self.port: int = port
|
|
|
|
self.reason: str = reason
|
2021-12-22 03:50:06 +00:00
|
|
|
super().__init__('%s %s' % (self.__class__.__name__, reason), **kwargs)
|
2019-12-02 06:46:00 +00:00
|
|
|
|
2021-12-21 23:54:31 +00:00
|
|
|
def response(self, _request: 'HttpParser') -> memoryview:
|
2021-12-24 19:00:40 +00:00
|
|
|
return BAD_GATEWAY_RESPONSE_PKT
|