Repository: litestar-org/litestar

Issue:
StaticFilesConfig and virtual directories
I'm trying to write a ``FileSystemProtocol`` to load files from the package data using [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/using.html#). But because ``directories`` is defined as ``DirectoryPath``, pydantic checks if the given directories exist in the local filesystem. 

This is not generally true, especially in any kind of virtual filesystem (e.g. a zipped package). I think this condition should be relaxed to support virtual filesystems.

https://github.com/starlite-api/starlite/blob/9bb6dcd57c10a591377cf8e3a537e9292566d5b9/starlite/config/static_files.py#L32


Discussion:
I agree. Do you want to submit a PR?

Resolving patch:
diff --git a/litestar/handlers/http_handlers/_utils.py b/litestar/handlers/http_handlers/_utils.py
--- a/litestar/handlers/http_handlers/_utils.py
+++ b/litestar/handlers/http_handlers/_utils.py
@@ -87,24 +87,17 @@ async def handler(
     return handler
 
 
-def create_generic_asgi_response_handler(
-    after_request: AfterRequestHookHandler | None,
-    cookies: frozenset[Cookie],
-) -> AsyncAnyCallable:
+def create_generic_asgi_response_handler(after_request: AfterRequestHookHandler | None) -> AsyncAnyCallable:
     """Create a handler function for Responses.
 
     Args:
         after_request: An after request handler.
-        cookies: A set of pre-defined cookies.
 
     Returns:
         A handler function.
     """
 
     async def handler(data: ASGIApp, **kwargs: Any) -> ASGIApp:
-        if hasattr(data, "set_cookie"):
-            for cookie in cookies:
-                data.set_cookie(**cookie.dict)
         return await after_request(data) if after_request else data  # type: ignore
 
     return handler
diff --git a/litestar/handlers/http_handlers/base.py b/litestar/handlers/http_handlers/base.py
--- a/litestar/handlers/http_handlers/base.py
+++ b/litestar/handlers/http_handlers/base.py
@@ -435,7 +435,7 @@ def get_response_handler(self, is_response_type_data: bool = False) -> Callable[
                 self._response_handler_mapping["default_handler"] = response_type_handler
             elif is_async_callable(return_annotation) or return_annotation is ASGIApp:
                 self._response_handler_mapping["default_handler"] = create_generic_asgi_response_handler(
-                    after_request=after_request, cookies=cookies
+                    after_request=after_request
                 )
             else:
                 self._response_handler_mapping["default_handler"] = create_data_handler(


Test patch:
diff --git a/tests/handlers/http/test_to_response.py b/tests/handlers/http/test_to_response.py
--- a/tests/handlers/http/test_to_response.py
+++ b/tests/handlers/http/test_to_response.py
@@ -131,7 +131,7 @@ def test_function() -> Response:
 async def test_to_response_returning_starlette_response(
     expected_response: StarletteResponse, anyio_backend: str
 ) -> None:
-    @get(path="/test", response_cookies=[Cookie(key="my-cookies", value="abc", path="/test")])
+    @get(path="/test")
     def test_function() -> StarletteResponse:
         return expected_response
 
@@ -143,7 +143,6 @@ def test_function() -> StarletteResponse:
         )
         assert isinstance(response, StarletteResponse)
         assert response is expected_response  # type: ignore[unreachable]
-        assert response.headers["set-cookie"] == "my-cookies=abc; Path=/test; SameSite=lax"
 
 
 async def test_to_response_returning_redirect_response(anyio_backend: str) -> None: