code: def test_redirect(serve_instance, base_path):
      app = FastAPI()
  
      route_prefix = f"/{base_path}"
  
      @serve.deployment()
      @serve.ingress(app)
      class D:
          @app.get("/")
          def root(self):
              return "hello from /"
  
          @app.get("/redirect")
          def redirect_root(self, request: Request):
              root_path = request.scope.get("root_path")
              if not root_path.endswith("/"):
                  root_path += "/"
              return RedirectResponse(url=root_path)
  
          @app.get("/redirect2")
          def redirect_twice(self, request: Request):
              root_path = request.scope.get("root_path")
              if root_path.endswith("/"):
                  root_path = root_path[:-1]
              return RedirectResponse(
                  url=root_path + app.url_path_for("redirect_root")
              )
  
      serve.run(D.bind(), route_prefix=route_prefix)
  
      if route_prefix != "/":
          route_prefix += "/"
  
      r = requests.get(f"http://localhost:8000{route_prefix}redirect")
      assert r.status_code == 200
      assert len(r.history) == 1
      assert r.json() == "hello from /"
  
      r = requests.get(f"http://localhost:8000{route_prefix}redirect2")
      assert r.status_code == 200
      assert len(r.history) == 2
      assert r.json() == "hello from /"
  
file_path: ray/python/ray/serve/tests/test_http_routes.py
imports: import time
  import pytest
  import requests
  from fastapi import FastAPI, Request
  from starlette.responses import RedirectResponse
  import ray
  from ray import serve
  from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
label_desc: Use image node_id 7 for calling a global function with example usage: test_redirect(serve_instance, base_path) and returns: str, RedirectResponse, RedirectResponse