HTTP purge request?

I was just curious to wonder how, if possible, one might issue an HTTP purge request method with Gatling/Scala to clear cache on a cache/proxy server as part of load/performance test setup/teardown.

Something like this in Java but Scala/Gatling equivalent:

http://stackoverflow.com/questions/12949457/how-do-i-do-http-purge-from-java

Or I suppose one should write a Java class implementing that and call that through Scala via Gatling instead?

We’ve just introduced before/after hook: https://github.com/excilys/gatling/commit/2be90cfee30cf8883c5d83b902d07dc57d154cb9

However, whatever code you write in your simulation body will be executed when the simulation is instanciated, so you can get the same effect as before hook.

You won’t be able to use Gatling DSL for this though.

I advise you write this directly in Scala, and use the HTTP client we ship: async-http-client:

import com.ning.http.client._

val client = new AsyncHttpClient

try {
client.executeRequest(new RequestBuilder(“PURGE”).setUrl(“http://foo.com”).build).get
} finally {
client.close
}

Cheers,

Stéphane