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 .base import HttpProtocolException
|
2021-11-14 21:47:12 +00:00
|
|
|
|
|
|
|
from ..codes import httpStatusCodes
|
|
|
|
from ..parser import HttpParser
|
2019-12-02 06:46:00 +00:00
|
|
|
|
|
|
|
from ...common.constants import PROXY_AGENT_HEADER_VALUE, PROXY_AGENT_HEADER_KEY
|
|
|
|
from ...common.utils import build_http_response
|
|
|
|
|
|
|
|
|
|
|
|
class ProxyAuthenticationFailed(HttpProtocolException):
|
|
|
|
"""Exception raised when Http Proxy auth is enabled and
|
|
|
|
incoming request doesn't present necessary credentials."""
|
|
|
|
|
2021-11-04 11:28:36 +00:00
|
|
|
RESPONSE_PKT = memoryview(
|
|
|
|
build_http_response(
|
|
|
|
httpStatusCodes.PROXY_AUTH_REQUIRED,
|
|
|
|
reason=b'Proxy Authentication Required',
|
|
|
|
headers={
|
|
|
|
PROXY_AGENT_HEADER_KEY: PROXY_AGENT_HEADER_VALUE,
|
|
|
|
b'Proxy-Authenticate': b'Basic',
|
|
|
|
b'Connection': b'close',
|
|
|
|
},
|
|
|
|
body=b'Proxy Authentication Required',
|
|
|
|
),
|
|
|
|
)
|
2019-12-02 06:46:00 +00:00
|
|
|
|
|
|
|
def response(self, _request: HttpParser) -> memoryview:
|
|
|
|
return self.RESPONSE_PKT
|