Skip to content

Commit e242994

Browse files
kennyputmanKenny Putman
andauthored
Make InertiaRequest inherit from HttpRequest (#78) (#84)
* Make InertiaRequest inherit from HttpRequest for compatibility (#78) * update InertiaRequest to inherit from HttpRequest using super() * remove unecessary headers property --------- Co-authored-by: Kenny Putman <[email protected]>
1 parent 13625d2 commit e242994

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

inertia/http.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from json import dumps as json_encode
44

55
from django.core.exceptions import ImproperlyConfigured
6-
from django.http import HttpResponse
6+
from django.http import HttpRequest, HttpResponse
77
from django.template.loader import render_to_string
88

99
from .helpers import deep_transform_callables, validate_type
@@ -25,20 +25,17 @@
2525
INERTIA_SSR_TEMPLATE = "inertia_ssr.html"
2626

2727

28-
class InertiaRequest:
28+
class InertiaRequest(HttpRequest):
2929
def __init__(self, request):
30-
self.request = request
31-
32-
def __getattr__(self, name):
33-
return getattr(self.request, name)
34-
35-
@property
36-
def headers(self):
37-
return self.request.headers
30+
super().__init__()
31+
self.__dict__.update(request.__dict__)
3832

3933
@property
4034
def inertia(self):
41-
return self.request.inertia.all() if hasattr(self.request, "inertia") else {}
35+
inertia_attr = self.__dict__.get("inertia")
36+
return (
37+
inertia_attr.all() if inertia_attr and hasattr(inertia_attr, "all") else {}
38+
)
4239

4340
def is_a_partial_render(self, component):
4441
return (
@@ -58,7 +55,7 @@ def is_inertia(self):
5855
def should_encrypt_history(self):
5956
return validate_type(
6057
getattr(
61-
self.request,
58+
self,
6259
INERTIA_REQUEST_ENCRYPT_HISTORY,
6360
settings.INERTIA_ENCRYPT_HISTORY,
6461
),

0 commit comments

Comments
 (0)