original_docstring:  Decorator that will check that the event.headers.origin is in origins; if the origin
      is valid, this decorator will add it to the response headers.
  
      Args:
          handler (func): a handler function with the signature (event, context) -> result
  
      Returns:
          handler (func): a lambda handler function that is authorized
      
docstring: Decorator that will check that the event.headers.origin is in origins; if the origin
  is valid, this decorator will add it to the response headers.
docstring_tokens: Decorator that will check that the event . headers . origin is in origins ; if the origin is valid this decorator will add it to the response headers .
code: def allow_origin_response(*origins):
      """ Decorator that will check that the event.headers.origin is in origins; if the origin
      is valid, this decorator will add it to the response headers.
  
      Args:
          handler (func): a handler function with the signature (event, context) -> result
  
      Returns:
          handler (func): a lambda handler function that is authorized
      """
      def allow_origin_handler(handler):
          def handler_wrapper(event, context, **kwargs):
              logger.debug(f'Checking origin for event: {event}')
  
              # Check Origin
              request_origin = utils.deep_get(event, 'headers', 'origin', ignore_case=True)
              if not any(re.match(o, str(request_origin)) for o in origins):
                  logger.warning(f'Invalid request origin: {request_origin}')
                  return {'statusCode': 403, 'body': 'Unknown origin.'}
  
              # call handler
              kwargs['request_origin'] = request_origin
              response = handler(event, context, **kwargs)
  
              if not isinstance(response, dict):
                  raise Exception(
                      f'Unsupported response type {type(response)}; response must be dict for *_response decorators.')
  
              # add origin to response headers
              current_headers = response.get('headers', {})
              cors_headers = {'Access-Control-Allow-Origin': request_origin,
                              'Access-Control-Allow-Credentials': 'true'}
              response['headers'] = {**current_headers, **cors_headers}
              return response
  
          return handler_wrapper
  
      return allow_origin_handler
code_tokens: def allow_origin_response ( * origins ) : def allow_origin_handler ( handler ) : def handler_wrapper ( event , context , ** kwargs ) : logger . debug ( f'Checking origin for event: {event}' ) request_origin = utils . deep_get ( event , 'headers' , 'origin' , ignore_case = True ) if not any ( re . match ( o , str ( request_origin ) ) for o in origins ) : logger . warning ( f'Invalid request origin: {request_origin}' ) return { 'statusCode' : 403 , 'body' : 'Unknown origin.' } kwargs [ 'request_origin' ] = request_origin response = handler ( event , context , ** kwargs ) if not isinstance ( response , dict ) : raise Exception ( f'Unsupported response type {type(response)}; response must be dict for *_response decorators.' ) current_headers = response . get ( 'headers' , { } ) cors_headers = { 'Access-Control-Allow-Origin' : request_origin , 'Access-Control-Allow-Credentials' : 'true' } response [ 'headers' ] = { ** current_headers , ** cors_headers } return response return handler_wrapper return allow_origin_handler
short_docstring: Decorator that will check that the event.headers.origin is in origins; if the origin
  is valid, this decorator will add it to the response headers.
short_docstring_tokens: Decorator that will check that the event . headers . origin is in origins ; if the origin is valid this decorator will add it to the response headers .
comment: """ Decorator that will check that the event.headers.origin is in origins; if the origin
      is valid, this decorator will add it to the response headers.
  
      Args:
          handler (func): a handler function with the signature (event, context) -> result
  
      Returns:
          handler (func): a lambda handler function that is authorized
      """$SEP$# Check Origin$SEP$# call handler$SEP$# add origin to response headers