HSTSEnforcer

class HSTSEnforcer(**properties: Any)

Superclasses: Object

Subclasses: HSTSEnforcerDB

Implemented Interfaces: SessionFeature

Constructors:

HSTSEnforcer(**properties)
new() -> Soup.HSTSEnforcer

Constructors

class HSTSEnforcer
classmethod new() HSTSEnforcer

Creates a new HSTSEnforcer.

The base HSTSEnforcer class does not support persistent storage of HSTS policies, see HSTSEnforcerDB for that.

Methods

class HSTSEnforcer
get_domains(session_policies: bool) list[str]

Gets a list of domains for which there are policies in enforcer.

Parameters:

session_policies – whether to include session policies

get_policies(session_policies: bool) list[HSTSPolicy]

Gets a list with the policies in enforcer.

Parameters:

session_policies – whether to include session policies

has_valid_policy(domain: str) bool

Gets whether hsts_enforcer has a currently valid policy for domain.

Parameters:

domain – a domain.

is_persistent() bool

Gets whether hsts_enforcer stores policies persistenly.

set_policy(policy: HSTSPolicy) None

Sets policy to hsts_enforcer.

If policy is expired, any existing HSTS policy for its host will be removed instead. If a policy existed for this host, it will be replaced. Otherwise, the new policy will be inserted. If the policy is a session policy, that is, one created with new_session_policy, the policy will not expire and will be enforced during the lifetime of hsts_enforcer’s Session.

Parameters:

policy – the policy of the HSTS host

set_session_policy(domain: str, include_subdomains: bool) None

Sets a session policy for domain.

A session policy is a policy that is permanent to the lifetime of hsts_enforcer’s Session and doesn’t expire.

Parameters:
  • domain – policy domain or hostname

  • include_subdomainsTrue if the policy applies on sub domains

Signals

class HSTSEnforcer.signals
changed(old_policy: HSTSPolicy, new_policy: HSTSPolicy) None

Emitted when hsts_enforcer changes.

If a policy has been added, new_policy will contain the newly-added policy and old_policy will be None. If a policy has been deleted, old_policy will contain the to-be-deleted policy and new_policy will be None. If a policy has been changed, old_policy will contain its old value, and new_policy its new value.

Note that you shouldn’t modify the policies from a callback to this signal.

Parameters:

Virtual Methods

class HSTSEnforcer
do_changed(old_policy: HSTSPolicy, new_policy: HSTSPolicy) None
Parameters:
  • old_policy

  • new_policy

do_has_valid_policy(domain: str) bool

Gets whether hsts_enforcer has a currently valid policy for domain.

Parameters:

domain – a domain.

do_is_persistent() bool

Gets whether hsts_enforcer stores policies persistenly.

Fields

class HSTSEnforcer
parent_instance