API
  • 03 Jan 2024
  • Dark
    Light

API

  • Dark
    Light

Article Summary

HumanSecurityEnforcer

The entity responsible for performing HUMAN enforcement.

HumanSecurityEnforcer.initialize()

A static function that creates a new instance of the HumanSecurityEnforcer class from a HumanSecurityConfiguration object.

Service Worker Syntax

HumanSecurityEnforcer.initialize(config: HumanSecurityConfiguration) => Promise<HumanSecurityEnforcer>
  • Parameters
    • params: HumanSecurityConfiguration
  • Returns a Promise resolving to a new instance of the HumanSecurityEnforcer class

ES Modules Syntax

HumanSecurityEnforcer.initialize(config: HumanSecurityConfiguration, env?: Environment) => Promise<HumanSecurityEnforcer>
  • Parameters
    • params: HumanSecurityConfiguration
    • env?: Environment
  • Returns a Promise resolving to a new instance of the HumanSecurityEnforcer class

enforce()

Executes the enforcement functionality, returning a request or response depending on which action should be taken by the worker.

The function returns a Request when...

  1. The request should not be blocked.
  2. The request should be blocked, but the enforcer has been configured to let these requests pass.

Note: Depending on the products and features enabled in the enforcer, the enforce() function may return a Request with additional headers that were not present on the original Request!

The function returns a Response when...

  1. The request should be blocked, and the response is a block page generated by the enforcer.
  2. The request was a first-party request, and the response is the first-party resource requested.

Note: Modifications can be made to this response as needed prior to returning it from the main function.

Service Worker Syntax

enforce(event: FetchEvent) => Promise<Request | Response>

ES Modules Syntax

enforce(executionContext: ExecutionContext, request: Request) => Promise<Request | Response>

postEnforce()

Performs any post-enforcement processing actions and final modifications to the response (i.e., setting cookies or headers) if needed.

Service Worker Syntax

postEnforce(event: FetchEvent, response: Response) => Promise<Response>

ES Modules Syntax

postEnforce(executionContext: ExecutionContext, response: Response) => Promise<Response>

Was this article helpful?

What's Next