diff --git a/proxy/plugin/grout_client.py b/proxy/plugin/grout_client.py index 109395123e..afbf5fed0b 100644 --- a/proxy/plugin/grout_client.py +++ b/proxy/plugin/grout_client.py @@ -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 @@ -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 diff --git a/proxy/proxy.py b/proxy/proxy.py index ce5509696b..d9dea572b1 100644 --- a/proxy/proxy.py +++ b/proxy/proxy.py @@ -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()