modify a view function so its response has the xframeoptions http header set to deny as long as the response doesn t already have that header set usage xframeoptionsdeny def someviewrequest modify a view function so its response has the xframeoptions http header set to sameorigin as long as the response doesn t already have that header set usage xframeoptionssameorigin def someviewrequest modify a view function by setting a response variable that instructs xframeoptionsmiddleware to not set the xframeoptions http header usage xframeoptionsexempt def someviewrequest modify a view function so its response has the x frame options http header set to deny as long as the response doesn t already have that header set usage xframe_options_deny def some_view request modify a view function so its response has the x frame options http header set to sameorigin as long as the response doesn t already have that header set usage xframe_options_sameorigin def some_view request modify a view function by setting a response variable that instructs xframeoptionsmiddleware to not set the x frame options http header usage xframe_options_exempt def some_view request
from functools import wraps

from asgiref.sync import iscoroutinefunction


def xframe_options_deny(view_func):
    

    if iscoroutinefunction(view_func):

        async def _view_wrapper(*args, **kwargs):
            response = await view_func(*args, **kwargs)
            if response.get("X-Frame-Options") is None:
                response["X-Frame-Options"] = "DENY"
            return response

    else:

        def _view_wrapper(*args, **kwargs):
            response = view_func(*args, **kwargs)
            if response.get("X-Frame-Options") is None:
                response["X-Frame-Options"] = "DENY"
            return response

    return wraps(view_func)(_view_wrapper)


def xframe_options_sameorigin(view_func):
    

    if iscoroutinefunction(view_func):

        async def _view_wrapper(*args, **kwargs):
            response = await view_func(*args, **kwargs)
            if response.get("X-Frame-Options") is None:
                response["X-Frame-Options"] = "SAMEORIGIN"
            return response

    else:

        def _view_wrapper(*args, **kwargs):
            response = view_func(*args, **kwargs)
            if response.get("X-Frame-Options") is None:
                response["X-Frame-Options"] = "SAMEORIGIN"
            return response

    return wraps(view_func)(_view_wrapper)


def xframe_options_exempt(view_func):
    

    if iscoroutinefunction(view_func):

        async def _view_wrapper(*args, **kwargs):
            response = await view_func(*args, **kwargs)
            response.xframe_options_exempt = True
            return response

    else:

        def _view_wrapper(*args, **kwargs):
            response = view_func(*args, **kwargs)
            response.xframe_options_exempt = True
            return response

    return wraps(view_func)(_view_wrapper)