-
-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ModifyRequestHeaderPlugin
(#1420)
* Add `ModifyRequestHeaderPlugin` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add to README * Fix lint issues shown by `Python3.11.8` --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e34da54
commit a7077cf
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- 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. | ||
""" | ||
from typing import Optional | ||
|
||
from ..http.proxy import HttpProxyBasePlugin | ||
from ..http.parser import HttpParser | ||
from ..common.utils import bytes_ | ||
from ..common.version import __version__ | ||
|
||
|
||
class ModifyRequestHeaderPlugin(HttpProxyBasePlugin): | ||
"""Modify request header before sending to upstream server.""" | ||
|
||
# def before_upstream_connection(self, request: HttpParser) -> Optional[HttpParser]: | ||
# """NOTE: Use this for HTTP only request headers modification.""" | ||
# request.add_header( | ||
# b"x-proxy-py-version", | ||
# bytes_(__version__), | ||
# ) | ||
# return request | ||
|
||
def handle_client_request(self, request: HttpParser) -> Optional[HttpParser]: | ||
"""NOTE: This is for HTTPS request headers modification when under TLS interception. | ||
For HTTPS requests, modification of request under TLS interception WILL NOT WORK | ||
through before_upstream_connection. | ||
""" | ||
request.add_header( | ||
b'x-proxy-py-version', | ||
bytes_(__version__), | ||
) | ||
return request |