Skip to content

Commit

Permalink
GroutClientBasePlugin return None for route to drop the request
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavsingh committed Oct 13, 2024
1 parent 16ab675 commit 79546ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions proxy/plugin/grout_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""


from typing import Tuple
from typing import Tuple, Optional

from proxy.proxy import GroutClientBasePlugin
from proxy.common.types import HostPort
Expand All @@ -25,14 +25,19 @@ def resolve_route(
request: HttpParser,
origin: HostPort,
server: HostPort,
) -> Tuple[str, HttpParser]:
print(request, origin, server, '->', route)
print(request.header(b'host'), request.path)
) -> Tuple[Optional[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.
#
# Optionally, you can also strip path like this:
# request.path = b"/"
#
# Return None for route to drop the request
# return None, request
#
return 'http://localhost:7001', request
3 changes: 2 additions & 1 deletion proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def resolve_route(
request: HttpParser,
origin: HostPort,
server: HostPort,
) -> Tuple[str, HttpParser]:
) -> Tuple[Optional[str], HttpParser]:
"""Returns a valid grout route string.
You MUST override this method. This method returns 2-tuple where
Expand All @@ -537,6 +537,7 @@ def resolve_route(
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.
Return None as "route" value to drop the request.
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
Expand Down

0 comments on commit 79546ff

Please sign in to comment.