Skip to content

Commit

Permalink
GroutClientBasePlugin ability to modify request object (#1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavsingh authored Oct 13, 2024
1 parent 0641864 commit 16ab675
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
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

from proxy.proxy import GroutClientBasePlugin
from proxy.common.types import HostPort
from proxy.http.parser.parser import HttpParser
Expand All @@ -23,11 +25,14 @@ def resolve_route(
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
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()

0 comments on commit 16ab675

Please sign in to comment.