Skip to content

Commit 1e45467

Browse files
fix asset view (#114)
1 parent 41048d1 commit 1e45467

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
1818

1919
## [Unreleased]
2020

21+
### Fixed
22+
23+
- Fixed asset serving view to properly stream files using `FileResponse` instead of reading file contents directly.
24+
2125
## [0.10.0]
2226

2327
### Added

src/django_bird/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def asset_view(request: HttpRequest, component_name: str, asset_filename: str):
2828
if not asset or not asset.path.exists():
2929
raise Http404("Asset not found")
3030

31-
with open(asset.path, "rb") as f:
32-
content = f.read()
31+
file = open(asset.path, "rb")
3332

34-
return FileResponse(content, content_type=asset.type.content_type)
33+
return FileResponse(file, content_type=asset.type.content_type)

tests/test_views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def test_get_css(templates_dir, client):
7272
assert response.status_code == HTTPStatus.OK
7373
assert response["Content-Type"] == "text/css"
7474

75+
content = b"".join(response.streaming_content).decode()
76+
77+
assert content == ".button { color: blue; }"
78+
7579

7680
def test_get_js(templates_dir, client):
7781
button = TestComponent(name="button", content="<button>Click me</button>").create(
@@ -86,6 +90,10 @@ def test_get_js(templates_dir, client):
8690
assert response.status_code == HTTPStatus.OK
8791
assert response["Content-Type"] == "application/javascript"
8892

93+
content = b"".join(response.streaming_content).decode()
94+
95+
assert content == "console.log('button');"
96+
8997

9098
def test_get_invalid_type(templates_dir, client):
9199
button = TestComponent(name="button", content="<button>Click me</button>").create(

0 commit comments

Comments
 (0)