Response headers x-inertia
Billybob opened this issue · comments
Hi,
If request is inertia (x-inertia=true), should add x-inertia=true in the response header ?
I added this in decorator
wrapped_default_response_headers = getattr(cls, "default_response_headers")
@property
def default_response_headers(self):
headers = wrapped_default_response_headers.fget(self)
headers["X-Inertia"] = True
return headers
it solved my problem
Maybe not a good idea to put X-Inertia by default in response_headers. Better to use middleware and put it under certain conditions
...
is_inertia = request.META.get('HTTP_X_INERTIA', False)
status = response.status_code
if is_inertia and status not in [404, 500]:
response["X-Inertia"] = True
...
return response
Yep, this needs fixing. I noticed I was actually adding this header in my own application code instead of in the drf_inertia. I have been trying to avoid middleware but it might be the best option in this case.