Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroutClientBasePlugin ability to modify request object #1489

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions proxy/plugin/grout_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"""


from typing import Tuple

Check warning on line 13 in proxy/plugin/grout_client.py

View check run for this annotation

Codecov / codecov/patch

proxy/plugin/grout_client.py#L13

Added line #L13 was not covered by tests

from proxy.proxy import GroutClientBasePlugin
from proxy.common.types import HostPort
from proxy.http.parser.parser import HttpParser
Expand All @@ -23,11 +25,14 @@
request: HttpParser,
origin: HostPort,
server: HostPort,
) -> str:
) -> Tuple[str, HttpParser]:
print(request, origin, server, '->', route)
print(request.header(b'host'), request.path)
# Send to localhost:7001 irrespective of the
# original "route" value provided to the grout client
# OR any custom host:upstream mapping provided through the
# --tunnel-route flags.
return 'http://localhost:7001'
#
# Optionally, you can also strip path like this:
# request.path = b"/"
return 'http://localhost:7001', request

Check warning on line 38 in proxy/plugin/grout_client.py

View check run for this annotation

Codecov / codecov/patch

proxy/plugin/grout_client.py#L38

Added line #L38 was not covered by tests
14 changes: 10 additions & 4 deletions proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,18 @@ def resolve_route(
request: HttpParser,
origin: HostPort,
server: HostPort,
) -> str:
) -> Tuple[str, HttpParser]:
"""Returns a valid grout route string.

You MUST override this method. For a simple pass through,
simply return the "route" argument value itself. You can also
return a dynamic value based upon "request" and "origin" information.
You MUST override this method. This method returns 2-tuple where
first value is the "route" and second the "request" object.

For a simple pass through, simply return the "route" argument value itself.
You can also return a dynamic value based upon "request" and "origin" information.
E.g. sending to different upstream services based upon request Host header.

You can also modify the original request object and return. Common examples
include strip-path scenario, where you would like to strip the path before
sending the request to upstream.
"""
raise NotImplementedError()
Loading