code: def test_metadata_preserved(serve_instance, use_fastapi: bool):
      """Check that status code, headers, and media type are preserved."""
  
      def hi_gen():
          for i in range(10):
              yield f"hi_{i}"
  
      if use_fastapi:
          app = FastAPI()
  
          @serve.deployment
          @serve.ingress(app)
          class SimpleGenerator:
              @app.get("/")
              def stream_hi(
                  self, request: Request
              ) -> StreamingResponse:
                  return StreamingResponse(
                      hi_gen(),
                      status_code=301,
                      headers={"hello": "world"},
                      media_type="foo/bar",
                  )
  
      else:
  
          @serve.deployment
          class SimpleGenerator:
              def __call__(self, request: Request) -> StreamingResponse:
                  return StreamingResponse(
                      hi_gen(),
                      status_code=301,
                      headers={"hello": "world"},
                      media_type="foo/bar",
                  )
  
      serve.run(SimpleGenerator.bind())
  
      r = requests.get("http://localhost:8000", stream=True)
      assert r.status_code == 301
      assert r.headers["hello"] == "world"
      assert r.headers["content-type"] == "foo/bar"
      for i, chunk in enumerate(r.iter_content(chunk_size=None)):
          assert chunk == f"hi_{i}".encode("utf-8")
  
file_path: ray/python/ray/serve/tests/test_streaming_response.py
imports: import asyncio
  import os
  from typing import AsyncGenerator
  import pytest
  import requests
  from fastapi import FastAPI
  from starlette.requests import Request
  from starlette.responses import StreamingResponse
  import ray
  from ray import serve
  from ray._private.test_utils import SignalActor
  from ray.serve.handle import RayServeHandle
label_desc: Use image node_id 3 for calling a global function with example usage: test_metadata_preserved(serve_instance, use_fastapi) and returns: StreamingResponse, StreamingResponse