aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/policies
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-08-11 21:55:46 +0200
committerWojtek Kosior <koszko@koszko.org>2022-08-11 21:55:46 +0200
commit1960eedc813b878ab193ff84ae10054ca4e0eccd (patch)
tree465b29e8702275a75dedd712f9f415270ccddd18 /src/hydrilla/proxy/policies
parenta38d19576c387e505cc468b20ca5b8bcf2fa4759 (diff)
downloadhaketilo-hydrilla-1960eedc813b878ab193ff84ae10054ca4e0eccd.tar.gz
haketilo-hydrilla-1960eedc813b878ab193ff84ae10054ca4e0eccd.zip
serve a stub of meta-site for proxy configuration
Diffstat (limited to 'src/hydrilla/proxy/policies')
-rw-r--r--src/hydrilla/proxy/policies/__init__.py2
-rw-r--r--src/hydrilla/proxy/policies/payload.py2
-rw-r--r--src/hydrilla/proxy/policies/web_ui.py62
3 files changed, 65 insertions, 1 deletions
diff --git a/src/hydrilla/proxy/policies/__init__.py b/src/hydrilla/proxy/policies/__init__.py
index 66e07ee..062ec56 100644
--- a/src/hydrilla/proxy/policies/__init__.py
+++ b/src/hydrilla/proxy/policies/__init__.py
@@ -13,3 +13,5 @@ from .payload_resource import PayloadResourcePolicyFactory
from .rule import RuleBlockPolicyFactory, RuleAllowPolicyFactory
from .fallback import FallbackAllowPolicy, FallbackBlockPolicy, ErrorBlockPolicy
+
+from .web_ui import WebUIPolicyFactory
diff --git a/src/hydrilla/proxy/policies/payload.py b/src/hydrilla/proxy/policies/payload.py
index ad0fa05..577c94e 100644
--- a/src/hydrilla/proxy/policies/payload.py
+++ b/src/hydrilla/proxy/policies/payload.py
@@ -292,7 +292,7 @@ class PayloadSuggestPolicy(PayloadAwarePolicy):
return http_messages.ProducedResponse(200, ((b'a', b'b'),), b'')
-@dc.dataclass(frozen=True, unsafe_hash=True) # type: ignore[misc]
+@dc.dataclass(frozen=True, unsafe_hash=True)
class PayloadPolicyFactory(PayloadAwarePolicyFactory):
"""...."""
def make_policy(self, haketilo_state: state.HaketiloState) \
diff --git a/src/hydrilla/proxy/policies/web_ui.py b/src/hydrilla/proxy/policies/web_ui.py
new file mode 100644
index 0000000..5040278
--- /dev/null
+++ b/src/hydrilla/proxy/policies/web_ui.py
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Policy for serving the web UI from within mitmproxy.
+#
+# This file is part of Hydrilla&Haketilo.
+#
+# Copyright (C) 2022 Wojtek Kosior
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+#
+# I, Wojtek Kosior, thereby promise not to sue for violation of this
+# file's license. Although I request that you do not make use this code
+# in a proprietary program, I am not going to enforce this in court.
+
+"""
+.....
+"""
+
+# Enable using with Python 3.7.
+from __future__ import annotations
+
+import dataclasses as dc
+import typing as t
+
+from ...translations import smart_gettext as _
+from .. import state
+from .. import http_messages
+from .. import web_ui
+from . import base
+
+
+@dc.dataclass(frozen=True)
+class WebUIPolicy(base.Policy):
+ """...."""
+ process_request: t.ClassVar[bool] = True
+
+ priority: t.ClassVar[base.PolicyPriority] = base.PolicyPriority._THREE
+
+ haketilo_state: state.HaketiloState
+
+ def consume_request(self, request_info: http_messages.RequestInfo) \
+ -> http_messages.ProducedResponse:
+ return web_ui.respond(request_info, self.haketilo_state)
+
+
+@dc.dataclass(frozen=True, unsafe_hash=True)
+class WebUIPolicyFactory(base.PolicyFactory):
+ """...."""
+ def make_policy(self, haketilo_state: state.HaketiloState) -> WebUIPolicy:
+ return WebUIPolicy(haketilo_state)