Skip to content

Commit 4117c5f

Browse files
authored
Add FilterByClientIpPlugin example (#381)
1 parent 568da5f commit 4117c5f

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

dashboard/src/proxy.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ html, body {
1515
}
1616

1717
main {
18-
height: 88%;
18+
height: 89.75%;
1919
}
2020

2121
section {

proxy/common/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
VERSION = (2, 2, 0)
11+
VERSION = (2, 2, 1)
1212
__version__ = '.'.join(map(str, VERSION[0:3]))

proxy/plugin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .web_server_route import WebServerPlugin
1919
from .reverse_proxy import ReverseProxyPlugin
2020
from .proxy_pool import ProxyPoolPlugin
21+
from .filter_by_client_ip import FilterByClientIpPlugin
2122

2223
__all__ = [
2324
'CacheResponsesPlugin',
@@ -31,4 +32,5 @@
3132
'WebServerPlugin',
3233
'ReverseProxyPlugin',
3334
'ProxyPoolPlugin',
35+
'FilterByClientIpPlugin',
3436
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
proxy.py
4+
~~~~~~~~
5+
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
6+
Network monitoring, controls & Application development, testing, debugging.
7+
8+
:copyright: (c) 2013-present by Abhinav Singh and contributors.
9+
:license: BSD, see LICENSE for more details.
10+
"""
11+
from typing import Optional
12+
13+
from ..http.exception import HttpRequestRejected
14+
from ..http.parser import HttpParser
15+
from ..http.codes import httpStatusCodes
16+
from ..http.proxy import HttpProxyBasePlugin
17+
18+
19+
class FilterByClientIpPlugin(HttpProxyBasePlugin):
20+
"""Drop traffic by inspecting incoming client IP address."""
21+
22+
FILTERED_IPS = ['127.0.0.1', '::1']
23+
24+
def before_upstream_connection(
25+
self, request: HttpParser) -> Optional[HttpParser]:
26+
if self.client.addr[0] in self.FILTERED_IPS:
27+
raise HttpRequestRejected(
28+
status_code=httpStatusCodes.I_AM_A_TEAPOT, reason=b'I\'m a tea pot',
29+
headers={
30+
b'Connection': b'close',
31+
}
32+
)
33+
return request
34+
35+
def handle_client_request(
36+
self, request: HttpParser) -> Optional[HttpParser]:
37+
return request
38+
39+
def handle_upstream_chunk(self, chunk: memoryview) -> memoryview:
40+
return chunk
41+
42+
def on_upstream_connection_close(self) -> None:
43+
pass

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""
1111
from setuptools import setup, find_packages
1212

13-
VERSION = (2, 2, 0)
13+
VERSION = (2, 2, 1)
1414
__version__ = '.'.join(map(str, VERSION[0:3]))
1515
__description__ = '''⚡⚡⚡Fast, Lightweight, Pluggable, TLS interception capable proxy server
1616
focused on Network monitoring, controls & Application development, testing, debugging.'''

0 commit comments

Comments
 (0)