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::
|
|
|
|
|
|
|
|
auth
|
|
|
|
http
|
2019-12-02 06:46:00 +00:00
|
|
|
"""
|
2021-12-21 23:54:31 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2019-12-02 06:46:00 +00:00
|
|
|
from .base import HttpProtocolException
|
2021-11-14 21:47:12 +00:00
|
|
|
|
|
|
|
from ..codes import httpStatusCodes
|
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
|
|
|
|
|
2021-12-21 23:54:31 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..parser import HttpParser
|
|
|
|
|
2019-12-02 06:46:00 +00:00
|
|
|
|
|
|
|
class ProxyAuthenticationFailed(HttpProtocolException):
|
2021-11-16 23:34:29 +00:00
|
|
|
"""Exception raised when HTTP Proxy auth is enabled and
|
2019-12-02 06:46:00 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
body=b'Proxy Authentication Required',
|
2021-12-21 21:26:52 +00:00
|
|
|
conn_close=True,
|
2021-11-04 11:28:36 +00:00
|
|
|
),
|
|
|
|
)
|
2019-12-02 06:46:00 +00:00
|
|
|
|
2021-12-21 23:54:31 +00:00
|
|
|
def response(self, _request: 'HttpParser') -> memoryview:
|
2019-12-02 06:46:00 +00:00
|
|
|
return self.RESPONSE_PKT
|