Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions hatchway/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.core.serializers.json import DjangoJSONEncoder
from django.http.response import HttpResponseBase
from django.utils.functional import cached_property

T = TypeVar("T")

Expand All @@ -25,19 +26,20 @@ def __init__(
self.data = data
self.encoder = encoder
self.json_dumps_params = json_dumps_params or {}
self.json_bytes = None
kwargs.setdefault("content_type", "application/json")
super().__init__(**kwargs)

@property
def content(self):
if self.json_bytes is None:
self.json_bytes = json.dumps(
self.data,
cls=self.encoder,
**self.json_dumps_params,
).encode("utf-8")
return self.json_bytes
return self.text.encode("utf-8")

@cached_property
def text(self):
return json.dumps(
self.data,
cls=self.encoder,
**self.json_dumps_params,
)

def __iter__(self):
yield self.content
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"cachetools>=5.3.3",
"cryptography>=42.0.5",
"dj-database-url>=2.1.0",
"django~=4.2.0",
"django~=5.2.0",
"django-cache-url>=3.4.5",
"django-cors-headers>=4.3.1",
"django-debug-toolbar>=4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ colorama==0.4.6 ; sys_platform == 'win32'
cryptography==45.0.2
distlib==0.3.9
dj-database-url==2.3.0
django==4.2.21
django==5.2.6
django-cache-url==3.4.5
django-cors-headers==4.7.0
django-debug-toolbar==5.2.0
Expand Down
2 changes: 1 addition & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ click==8.2.1
colorama==0.4.6 ; sys_platform == 'win32'
cryptography==45.0.2
dj-database-url==2.3.0
django==4.2.21
django==5.2.6
django-cache-url==3.4.5
django-cors-headers==4.7.0
django-debug-toolbar==5.2.0
Expand Down
4 changes: 2 additions & 2 deletions takahe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ class Settings(BaseSettings):

ROBOTS_TXT_DISALLOWED_USER_AGENTS = SETUP.ROBOTS_TXT_DISALLOWED_USER_AGENTS

CORS_ORIGIN_ALLOW_ALL = True # Temporary
CORS_ORIGIN_WHITELIST = SETUP.CORS_HOSTS
CORS_ALLOW_ALL_ORIGINS = True # Temporary
CORS_ALLOWED_ORIGINS = SETUP.CORS_HOSTS
CORS_ALLOW_CREDENTIALS = True
CORS_PREFLIGHT_MAX_AGE = 604800
CORS_EXPOSE_HEADERS = ("link",)
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def _test_settings(settings):
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"
},
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
}
settings.SETUP.MAIN_DOMAIN = "example.com"
settings.MAIN_DOMAIN = "example.com"
Expand Down