Skip to content

Commit 79546ff

Browse files
committed
GroutClientBasePlugin return None for route to drop the request
1 parent 16ab675 commit 79546ff

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

proxy/plugin/grout_client.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""
1111

1212

13-
from typing import Tuple
13+
from typing import Tuple, Optional
1414

1515
from proxy.proxy import GroutClientBasePlugin
1616
from proxy.common.types import HostPort
@@ -25,14 +25,19 @@ def resolve_route(
2525
request: HttpParser,
2626
origin: HostPort,
2727
server: HostPort,
28-
) -> Tuple[str, HttpParser]:
29-
print(request, origin, server, '->', route)
30-
print(request.header(b'host'), request.path)
28+
) -> Tuple[Optional[str], HttpParser]:
29+
# print(request, origin, server, '->', route)
30+
# print(request.header(b'host'), request.path)
31+
#
3132
# Send to localhost:7001 irrespective of the
3233
# original "route" value provided to the grout client
3334
# OR any custom host:upstream mapping provided through the
3435
# --tunnel-route flags.
3536
#
3637
# Optionally, you can also strip path like this:
3738
# request.path = b"/"
39+
#
40+
# Return None for route to drop the request
41+
# return None, request
42+
#
3843
return 'http://localhost:7001', request

proxy/proxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def resolve_route(
528528
request: HttpParser,
529529
origin: HostPort,
530530
server: HostPort,
531-
) -> Tuple[str, HttpParser]:
531+
) -> Tuple[Optional[str], HttpParser]:
532532
"""Returns a valid grout route string.
533533
534534
You MUST override this method. This method returns 2-tuple where
@@ -537,6 +537,7 @@ def resolve_route(
537537
For a simple pass through, simply return the "route" argument value itself.
538538
You can also return a dynamic value based upon "request" and "origin" information.
539539
E.g. sending to different upstream services based upon request Host header.
540+
Return None as "route" value to drop the request.
540541
541542
You can also modify the original request object and return. Common examples
542543
include strip-path scenario, where you would like to strip the path before

0 commit comments

Comments
 (0)