Gatling Java - HttpProtocolBuilder DenyList

Hello,
I need to filter specific domain requests in my scenario. I have tried the HAR file-based recording and added the DenyList (like “.**\fonts. example.com.*\”) . On HttpProtocolBuilder I could see an entry for the exclusion in the inferHtmlResources. still while running the scenario, hits are going to the example.com domain. how do exclude specific requests based on domain name or pattern?

In the example provided, I tried to enter a single star but it is not showing up on the post so added an escape pattern with one more “*”.

Thanks

As the documentation states:

You can also specify AllowList and DenyList based on Java Regex patterns

You’re not using the correct pattern syntax.

Please check:

Thanks for sharing the details, I have changed the pattern and tried it on the Java Regular Expression Tester it is matching with the absolute request URL. but still, request are hitting other domains on the ScenarioBuilder. anything I am missing?

private HttpProtocolBuilder httpProtocol = http
.baseUrl(“https://site1.123.com”)
.inferHtmlResources(DenyList (“.*example.*”))
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.9”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36”);

Please provide a proper reproducer as instructed here. Without one, we’re just shooting in the dark.

I have used the HAR Converter as Recorder mode to create the Gatling simulation class, my requirement is to allow the request only to the domain 123.com and deny the request to the example.com domain. I tried to add a pattern ( inferHtmlResources(DenyList(“.example.”)) ) to the HttpProtocolBuilder. While running the scenario request are hitting both the 123.com and example.com domains.

package example;

import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;

public class ExampleLogin extends Simulation {

private HttpProtocolBuilder httpProtocol = http
.baseUrl(“https://site1.123.com”)
.inferHtmlResources(DenyList(“.*example.*”))
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.9”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36”);

private ScenarioBuilder scn = scenario(“HomePage”)
.exec(
http(“Home”)
.get(“/”)
.resources(
http(“fonts”)
.get( “https://fonts.example.com/text.regular&text.medium”),
http(“cdn”)
.get(“https://cdn.example.com/env=1&plan_id=main_data_plan&plan_version=1”),
http(“cookie”)
.get(“https://example.com/consent/loader.js?mountpoint=cookie”)
)
);

{
setUp(scn.injectOpen(atOnceUsers(1))).protocols(httpProtocol);
}
}

If you add in resources()

this GET will be forced so if you want all resources but omitted that for pattern .*example.* your code should look like below:

package example;

import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;

public class ExampleLogin extends Simulation {

    private HttpProtocolBuilder httpProtocol = http
            .baseUrl("https://site1.123.com")
            .inferHtmlResources(DenyList(".*example.*"))
            .acceptEncodingHeader("gzip, deflate")
            .acceptLanguageHeader("en-US,en;q=0.9")
            .userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36");

    private ScenarioBuilder scn = scenario("HomePage")
            .exec(
                    http("Home")
                            .get("/")
                            .resources()
            );

    {
        setUp(scn.injectOpen(atOnceUsers(1))).protocols(httpProtocol);
    }
}

Thanks for your response, I have removed the example domains get() inside the resources. now only baseurl requests are present still I could see requests to other domains. In my case it is retrieving the other domain URL from the base URL response

private ScenarioBuilder scn = scenario(“HomePage”)
.exec(
http(“Home”)
.get(“/”)
.resources()
);

Is it possible to filter the request to the specific domains on the class level?

So you must prepare better pattern for DenyList()
Example → Case0012DenySomeResourcesSimulation
or
You can toresign from using inferHtmlResources and make own .resources() with resources what you want :slight_smile:

Example → Case0008AsyncReqResourcesSimulation

Thanks for sharing the examples. It gave me insight about inferHtmlResources.

If my Examples helped with your problem please set my post as solution.