aws_lambda_decorators/decorators.py
def hsts(max_age: int = None):
    """
        Adds HSTS header to the response of the decorated function

        Usage:
            @hsts(max_age=86400)
            def func(my_param)
                pass

        Args:
            max_age: An integer to indicate the time browser should remember your domain as HTTPS only communication.
            If not specified default value of 2 years is used.

        Returns:
            The original decorated function response with the additional hsts header
    """
    def decorator(func):
        def wrapper(*args, **kwargs):
            response = func(*args, **kwargs)

            if isinstance(response, dict):
                headers_key = find_key_case_insensitive("headers", response)

                resp_headers = response[headers_key] if headers_key in response else {}

                header_key = find_key_case_insensitive("Strict-Transport-Security", resp_headers)
                header_value = f"max-age={max_age}" if max_age else "max-age=63072000"
                resp_headers[header_key] = header_value
                response[headers_key] = resp_headers
                return response
            else:
                LOGGER.error(NON_DICT_LOG_MESSAGE)
                return failure(HSTS_NON_DICT_ERROR, HTTPStatus.INTERNAL_SERVER_ERROR)
        return wrapper
    return decorator

        Adds HSTS header to the response of the decorated function

        Usage:
            @hsts(max_age=86400)
            def func(my_param)
                pass

        Args:
            max_age: An integer to indicate the time browser should remember your domain as HTTPS only communication.
            If not specified default value of 2 years is used.

        Returns:
            The original decorated function response with the additional hsts header
    
Adds HSTS header to the response of the decorated function
Usage:
@hsts(max_age=86400)
def func(my_param)
pass

An integer to indicate the time browser should remember your domain as HTTPS only communication.
If not specified default value of 2 years is used.

The original decorated function response with the additional hsts header
Adds HSTS header to the response of the decorated function Usage : @hsts ( max_age = 86400 ) def func ( my_param ) pass An integer to indicate the time browser should remember your domain as HTTPS only communication . If not specified default value of 2 years is used . The original decorated function response with the additional hsts header
def hsts(max_age: int = None):
    def decorator(func):
        def wrapper(*args, **kwargs):
            response = func(*args, **kwargs)
            if isinstance(response, dict):
                headers_key = find_key_case_insensitive("headers", response)
                resp_headers = response[headers_key] if headers_key in response else {}
                header_key = find_key_case_insensitive("Strict-Transport-Security", resp_headers)
                header_value = f"max-age={max_age}" if max_age else "max-age=63072000"
                resp_headers[header_key] = header_value
                response[headers_key] = resp_headers
                return response
            else:
                LOGGER.error(NON_DICT_LOG_MESSAGE)
                return failure(HSTS_NON_DICT_ERROR, HTTPStatus.INTERNAL_SERVER_ERROR)
        return wrapper
    return decorator
def hsts ( max_age : int = None ) : def decorator ( func ) : def wrapper ( * args , ** kwargs ) : response = func ( * args , ** kwargs ) if isinstance ( response , dict ) : headers_key = find_key_case_insensitive ( "headers" , response ) resp_headers = response [ headers_key ] if headers_key in response else { } header_key = find_key_case_insensitive ( "Strict-Transport-Security" , resp_headers ) header_value = f"max-age={max_age}" if max_age else "max-age=63072000" resp_headers [ header_key ] = header_value response [ headers_key ] = resp_headers return response else : LOGGER . error ( NON_DICT_LOG_MESSAGE ) return failure ( HSTS_NON_DICT_ERROR , HTTPStatus . INTERNAL_SERVER_ERROR ) return wrapper return decorator
Adds HSTS header to the response of the decorated function
Usage:
@hsts(max_age=86400)
def func(my_param)
pass
Adds HSTS header to the response of the decorated function Usage : @hsts ( max_age = 86400 ) def func ( my_param ) pass
"""
        Adds HSTS header to the response of the decorated function

        Usage:
            @hsts(max_age=86400)
            def func(my_param)
                pass

        Args:
            max_age: An integer to indicate the time browser should remember your domain as HTTPS only communication.
            If not specified default value of 2 years is used.

        Returns:
            The original decorated function response with the additional hsts header
    """
max_age
int