Class Blocking

java.lang.Object
datadog.appsec.api.blocking.Blocking

public class Blocking extends Object
Functionality related to blocking requests. This functionality is available if and only if the AppSec subsystem is enabled.
  • Method Details

    • forUser

      public static Blocking.UserBlockingSpec forUser(String userId)
      Starts a user-blocking action.
      Parameters:
      userId - a non-null unique identifier for the currently identified user
      Returns:
      an object through which the action in case of a match can be controlled
    • tryCommitBlockingResponse

      public static boolean tryCommitBlockingResponse(int statusCode, BlockingContentType contentType, Map<String,String> extraHeaders)
      Tries to commit an HTTP response with the specified status code and content type. No exception should escape if this fails.

      This method returns false if blocking cannot be attempted because of the following conditions:

      • there is no span available,
      • blocking is not supported for the server being used, or
      • the blocking service is otherwise incapable, in principle, of blocking (e.g. it's a no-op implementation).

      This method does not return false if a blocking response has already been committed, or if there is an error when trying to write the response. This is because the writing may happen asynchronously, after the caller has returned.

      Parameters:
      statusCode - the status code of the response
      contentType - the content-type of the response.
      extraHeaders - map of headers to set in the response
      Returns:
      whether blocking was/will be attempted
    • tryCommitBlockingResponse

      public static boolean tryCommitBlockingResponse(int statusCode, BlockingContentType contentType)
      Equivalent to calling tryCommitBlockingResponse(int, BlockingContentType, Map<String, String>) with the last parameter being an empty map.
      Parameters:
      statusCode - the status code of the response
      contentType - the content-type of the response.
      Returns:
      whether blocking was/will be attempted
    • setBlockingService

      public static void setBlockingService(BlockingService service)
      Controls the implementation for blocking. The AppSec subsystem calls this method on startup. This can be called explicitly for e.g. testing purposes.
      Parameters:
      service - the implementation for blocking.