def content(*args, **kwargs):
    # TODO(ikutukov): this decorator is not coherent and doing more
    # than just a response mimetype setting via type-specific content_json
    # method that perform validation.
    # Before you start to implement handler business logic ensure that
    # @content decorator not already doing what you are planning to write.
    # I think that validation routine and common http headers formation not
    # depending on each other and should be decoupled. At least they should
    # not be under one decorator with abstract name.

    exact_mimetypes = None
    if len(args) >= 1 and isinstance(args[0], list):
        exact_mimetypes = args[0]

    @decorator
    def wrapper(func, *args, **kwargs):
        accept = web.ctx.env.get("HTTP_ACCEPT", "application/json")
        accepted_types = [
            "application/json",
            "*/*"
        ]
        if exact_mimetypes and isinstance(exact_mimetypes, list):
            accepted_types = exact_mimetypes
        if any(map(lambda m: m in accept, accepted_types)):
            return content_json(func, *args, **kwargs)
        else:
            raise BaseHandler.http(415)

    # case of @content without arguments, meaning arg[0] to be callable
    # handler
    if len(args) >= 1 and callable(args[0]):
        return wrapper(args[0], *args[1:], **kwargs)

    # case of @content(["mimetype"]) with explicit arguments
    return wrapper
Set context-type of response based on Accept header
dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/api/v1/handlers/base.py/content