How to retry requests that were blocked
  • 26 Feb 2023
  • Dark
    Light

How to retry requests that were blocked

  • Dark
    Light

v3.0

What is the Automatic Interceptor?
The "Automatic Interceptor" is a feature that allows the SDK to intercept URL requests from your app. Enabling this will reduce the amount of code you will have to write as part of the SDK integration.

URL Requests that were blocked by PerimeterX don't reach your server. Therefore, after the user solves the challenge you may want to retry those requests. You can configure the behavior of the SDK when requests are blocked:

  1. Delay response until challenge is solved or cancelled - setting this in the policy will delay the error response to your request's handler until the user solves or cancels the challenge. Then, the error you will receive contains the information regarding the challenge result (solved or cancelled).
    policy.urlRequestInterceptionType = .interceptWithDelayedResponse
    policy.urlRequestInterceptionType = PXPolicyUrlRequestInterceptionTypeInterceptWithDelayedResponse;
  1. Intercept and retry request - setting this in the policy will delay the error response to your request's handler until the user solves or cancels the challenge. In addition, when the challenge is solved, the SDK will send the original request one more time. Your request's handler should receive the response from your server without knowing that the request was blocked and sent again. You should note that when the challenge is cancelled or when the second request is also blocked, then the behavior will be the same as the "delay the response until the challenge is solved or cancelled" configuration.
­čÜžRetry request on URLSession.shared
When the SDK retries the original request, it will use the URLSession.shared. Take this in consideration if you are using a custom URL Session object in your project.
policy.urlRequestInterceptionType = .interceptAndRetryRequest
policy.urlRequestInterceptionType = PXPolicyUrlRequestInterceptionTypeInterceptAndRetryRequest;

­čÜžDisable the request's timeout
In order to delay the request's response to your handler until the user interacts with the challenge, you must disable the request's timeout. Otherwise, your handler will receive a timeout error and you might not know that your request was blocked nor the challenge was solved/cancelled.

How to disable the URL request's timeout

URLSession:

var urlRequest = URLRequest()
urlRequest.timeoutInterval = 0
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.timeoutInterval = 0

Alamofire:

AF.request("<url>", headers: HTTPHeaders(headers)) { $0.timeoutInterval = 0 }

Was this article helpful?