Skip to content

Commit 16ab675

Browse files
authored
GroutClientBasePlugin ability to modify request object (#1489)
1 parent 0641864 commit 16ab675

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

proxy/plugin/grout_client.py

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

1212

13+
from typing import Tuple
14+
1315
from proxy.proxy import GroutClientBasePlugin
1416
from proxy.common.types import HostPort
1517
from proxy.http.parser.parser import HttpParser
@@ -23,11 +25,14 @@ def resolve_route(
2325
request: HttpParser,
2426
origin: HostPort,
2527
server: HostPort,
26-
) -> str:
28+
) -> Tuple[str, HttpParser]:
2729
print(request, origin, server, '->', route)
2830
print(request.header(b'host'), request.path)
2931
# Send to localhost:7001 irrespective of the
3032
# original "route" value provided to the grout client
3133
# OR any custom host:upstream mapping provided through the
3234
# --tunnel-route flags.
33-
return 'http://localhost:7001'
35+
#
36+
# Optionally, you can also strip path like this:
37+
# request.path = b"/"
38+
return 'http://localhost:7001', request

proxy/proxy.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,18 @@ def resolve_route(
528528
request: HttpParser,
529529
origin: HostPort,
530530
server: HostPort,
531-
) -> str:
531+
) -> Tuple[str, HttpParser]:
532532
"""Returns a valid grout route string.
533533
534-
You MUST override this method. For a simple pass through,
535-
simply return the "route" argument value itself. You can also
536-
return a dynamic value based upon "request" and "origin" information.
534+
You MUST override this method. This method returns 2-tuple where
535+
first value is the "route" and second the "request" object.
536+
537+
For a simple pass through, simply return the "route" argument value itself.
538+
You can also return a dynamic value based upon "request" and "origin" information.
537539
E.g. sending to different upstream services based upon request Host header.
540+
541+
You can also modify the original request object and return. Common examples
542+
include strip-path scenario, where you would like to strip the path before
543+
sending the request to upstream.
538544
"""
539545
raise NotImplementedError()

0 commit comments

Comments
 (0)