2019-11-30 05:28:31 +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.
|
|
|
|
"""
|
2022-01-21 16:59:34 +00:00
|
|
|
from typing import List, Tuple
|
2021-11-19 18:35:24 +00:00
|
|
|
|
2022-01-21 16:59:34 +00:00
|
|
|
from ..http.server import ReverseProxyBasePlugin
|
2019-11-30 05:28:31 +00:00
|
|
|
|
2021-11-19 18:35:24 +00:00
|
|
|
|
2022-01-21 16:59:34 +00:00
|
|
|
# TODO: We must use nginx python parser and
|
|
|
|
# make this plugin nginx.conf complaint.
|
|
|
|
REVERSE_PROXY_LOCATION: str = r'/get$'
|
|
|
|
# Randomly choose either http or https upstream endpoint.
|
|
|
|
#
|
|
|
|
# This is just to demonstrate that both http and https upstream
|
|
|
|
# reverse proxy works.
|
|
|
|
REVERSE_PROXY_PASS = [
|
|
|
|
b'http://httpbin.org/get',
|
|
|
|
b'https://httpbin.org/get',
|
|
|
|
]
|
2021-11-05 10:25:56 +00:00
|
|
|
|
|
|
|
|
2022-01-21 16:59:34 +00:00
|
|
|
class ReverseProxyPlugin(ReverseProxyBasePlugin):
|
|
|
|
"""This example plugin is equivalent to following Nginx configuration::
|
2019-11-30 05:28:31 +00:00
|
|
|
|
2021-11-16 23:34:29 +00:00
|
|
|
```text
|
2019-11-30 05:28:31 +00:00
|
|
|
location /get {
|
|
|
|
proxy_pass http://httpbin.org/get
|
|
|
|
}
|
2021-11-16 23:34:29 +00:00
|
|
|
```
|
2019-11-30 05:28:31 +00:00
|
|
|
|
2022-01-21 16:59:34 +00:00
|
|
|
Update the routes config before.
|
2019-11-30 05:28:31 +00:00
|
|
|
"""
|
|
|
|
|
2022-01-21 16:59:34 +00:00
|
|
|
def routes(self) -> List[Tuple[str, List[bytes]]]:
|
|
|
|
return [(REVERSE_PROXY_LOCATION, REVERSE_PROXY_PASS)]
|