File tree 4 files changed +69
-1
lines changed
4 files changed +69
-1
lines changed Original file line number Diff line number Diff line change 59
59
- [ Proxy Pool Plugin] ( #proxypoolplugin )
60
60
- [ Filter By Client IP Plugin] ( #filterbyclientipplugin )
61
61
- [ Modify Chunk Response Plugin] ( #modifychunkresponseplugin )
62
+ - [ Modify Request Header Plugin] ( #modifyrequestheaderplugin )
62
63
- [ Cloudflare DNS Resolver Plugin] ( #cloudflarednsresolverplugin )
63
64
- [ Custom DNS Resolver Plugin] ( #customdnsresolverplugin )
64
65
- [ Custom Network Interface] ( #customnetworkinterface )
@@ -932,6 +933,31 @@ plugin
932
933
933
934
Modify ` ModifyChunkResponsePlugin ` to your taste. Example, instead of sending hard-coded chunks, parse and modify the original ` JSON ` chunks received from the upstream server.
934
935
936
+ ### ModifyRequestHeaderPlugin
937
+
938
+ This plugin demonstrate how to modify outgoing HTTPS request headers under TLS interception mode.
939
+
940
+ Start ` proxy.py ` as:
941
+
942
+ ``` console
943
+ ❯ proxy \
944
+ --plugins proxy.plugin.ModifyRequestHeaderPlugin \
945
+ ... [TLS interception flags] ...
946
+ ```
947
+
948
+ Verify using ` curl -x localhost:8899 --cacert ca-cert.pem https://httpbin.org/get ` :
949
+
950
+ ``` console
951
+ {
952
+ "args": {},
953
+ "headers": {
954
+ ... [redacted] ...,
955
+ "X-Proxy-Py-Version": "2.4.4rc6.dev15+gf533c711"
956
+ },
957
+ ... [redacted] ...
958
+ }
959
+ ```
960
+
935
961
### CloudflareDnsResolverPlugin
936
962
937
963
This plugin uses ` Cloudflare ` hosted ` DNS-over-HTTPS ` [ API] ( https://developers.cloudflare.com/1.1.1.1/encrypted-dns/dns-over-https/make-api-requests/dns-json ) (json).
Original file line number Diff line number Diff line change @@ -217,7 +217,7 @@ def on_client_data(self, raw: memoryview) -> None:
217
217
self .pipeline_request = None
218
218
219
219
def on_response_chunk (self , chunk : List [memoryview ]) -> List [memoryview ]:
220
- self ._response_size += sum ([ len (c ) for c in chunk ] )
220
+ self ._response_size += sum (len (c ) for c in chunk )
221
221
return chunk
222
222
223
223
def on_client_connection_close (self ) -> None :
Original file line number Diff line number Diff line change 32
32
from .filter_by_client_ip import FilterByClientIpPlugin
33
33
from .filter_by_url_regex import FilterByURLRegexPlugin
34
34
from .modify_chunk_response import ModifyChunkResponsePlugin
35
+ from .modify_request_header import ModifyRequestHeaderPlugin
35
36
from .redirect_to_custom_server import RedirectToCustomServerPlugin
36
37
37
38
53
54
'CustomDnsResolverPlugin' ,
54
55
'CloudflareDnsResolverPlugin' ,
55
56
'ProgramNamePlugin' ,
57
+ 'ModifyRequestHeaderPlugin' ,
56
58
]
Original file line number Diff line number Diff line change
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 .proxy import HttpProxyBasePlugin
14
+ from ..http .parser import HttpParser
15
+ from ..common .utils import bytes_
16
+ from ..common .version import __version__
17
+
18
+
19
+ class ModifyRequestHeaderPlugin (HttpProxyBasePlugin ):
20
+ """Modify request header before sending to upstream server."""
21
+
22
+ # def before_upstream_connection(self, request: HttpParser) -> Optional[HttpParser]:
23
+ # """NOTE: Use this for HTTP only request headers modification."""
24
+ # request.add_header(
25
+ # b"x-proxy-py-version",
26
+ # bytes_(__version__),
27
+ # )
28
+ # return request
29
+
30
+ def handle_client_request (self , request : HttpParser ) -> Optional [HttpParser ]:
31
+ """NOTE: This is for HTTPS request headers modification when under TLS interception.
32
+
33
+ For HTTPS requests, modification of request under TLS interception WILL NOT WORK
34
+ through before_upstream_connection.
35
+ """
36
+ request .add_header (
37
+ b'x-proxy-py-version' ,
38
+ bytes_ (__version__ ),
39
+ )
40
+ return request
You can’t perform that action at this time.
0 commit comments