Repository: litestar-org/litestar

Issue:
Bug: StaticFiles sends files as `content-disposition: 'attachment'` in html-mode
**Describe the bug**
When using `StaticFiles` in html-mode, files are being sent with `content-disposition: 'attachment'`

**To Reproduce**
Create an `html/index.html` file. Run:

```python
from starlite import Starlite, StaticFilesConfig, TestClient

app = Starlite(
    static_files_config=[StaticFilesConfig(path="/", directories=["html"], html_mode=True)], route_handlers=[]
)

with TestClient(app=app) as client:
    res = client.get("/index.html")
    assert not res.headers["content-disposition"].startswith("attachment")
```

Bug: StaticFiles sends files as `content-disposition: 'attachment'` in html-mode
**Describe the bug**
When using `StaticFiles` in html-mode, files are being sent with `content-disposition: 'attachment'`

**To Reproduce**
Create an `html/index.html` file. Run:

```python
from starlite import Starlite, StaticFilesConfig, TestClient

app = Starlite(
    static_files_config=[StaticFilesConfig(path="/", directories=["html"], html_mode=True)], route_handlers=[]
)

with TestClient(app=app) as client:
    res = client.get("/index.html")
    assert not res.headers["content-disposition"].startswith("attachment")
```



Discussion:

Resolving patch:
diff --git a/starlite/static_files/base.py b/starlite/static_files/base.py
--- a/starlite/static_files/base.py
+++ b/starlite/static_files/base.py
@@ -8,6 +8,7 @@
 from starlite.utils.file import FileSystemAdapter
 
 if TYPE_CHECKING:
+    from typing_extensions import Literal
 
     from starlite.types import Receive, Scope, Send
     from starlite.types.composite_types import PathType
@@ -61,12 +62,15 @@ async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> No
         filename = split_path[-1]
         joined_path = join(*split_path)  # noqa: PL118
         resolved_path, fs_info = await self.get_fs_info(directories=self.directories, file_path=joined_path)
+        content_disposition_type: "Literal['inline', 'attachment']" = "attachment"
 
-        if fs_info and fs_info["type"] == "directory" and self.is_html_mode:
-            filename = "index.html"
-            resolved_path, fs_info = await self.get_fs_info(
-                directories=self.directories, file_path=join(resolved_path or joined_path, filename)
-            )
+        if self.is_html_mode:
+            content_disposition_type = "inline"
+            if fs_info and fs_info["type"] == "directory":
+                filename = "index.html"
+                resolved_path, fs_info = await self.get_fs_info(
+                    directories=self.directories, file_path=join(resolved_path or joined_path, filename)
+                )
 
         if fs_info and fs_info["type"] == "file":
             await FileResponse(
@@ -75,6 +79,7 @@ async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> No
                 file_system=self.adapter.file_system,
                 filename=filename,
                 is_head_response=scope["method"] == "HEAD",
+                content_disposition_type=content_disposition_type,
             )(scope, receive, send)
             return
 
@@ -89,6 +94,7 @@ async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> No
                     filename=filename,
                     is_head_response=scope["method"] == "HEAD",
                     status_code=HTTP_404_NOT_FOUND,
+                    content_disposition_type=content_disposition_type,
                 )(scope, receive, send)
                 return
 


Test patch:
diff --git a/tests/static_files/test_file_serving_resolution.py b/tests/static_files/test_file_serving_resolution.py
--- a/tests/static_files/test_file_serving_resolution.py
+++ b/tests/static_files/test_file_serving_resolution.py
@@ -149,3 +149,16 @@ def test_static_files_response_mimetype(tmpdir: "Path", extension: str) -> None:
         assert expected_mime_type
         assert response.status_code == HTTP_200_OK
         assert response.headers["content-type"].startswith(expected_mime_type)
+
+
+@pytest.mark.parametrize("html_mode,disposition", [(True, "inline"), (False, "attachment")])
+def test_static_files_response_content_disposition(tmpdir: "Path", html_mode: bool, disposition: str) -> None:
+    fn = "test.txt"
+    path = tmpdir / fn
+    path.write_text("content", "utf-8")
+    static_files_config = StaticFilesConfig(path="/static", directories=[tmpdir], html_mode=html_mode)
+
+    with create_test_client([], static_files_config=static_files_config) as client:
+        response = client.get(f"/static/{fn}")
+        assert response.status_code == HTTP_200_OK
+        assert response.headers["content-disposition"].startswith(disposition)
diff --git a/tests/static_files/test_html_mode.py b/tests/static_files/test_html_mode.py
--- a/tests/static_files/test_html_mode.py
+++ b/tests/static_files/test_html_mode.py
@@ -26,6 +26,7 @@ def test_staticfiles_is_html_mode(tmpdir: "Path", file_system: "FileSystemProtoc
         assert response.status_code == HTTP_200_OK
         assert response.text == "content"
         assert response.headers["content-type"] == "text/html; charset=utf-8"
+        assert response.headers["content-disposition"].startswith("inline")
 
 
 @pytest.mark.parametrize("file_system", (BaseLocalFileSystem(), LocalFileSystem()))