# Getting URL parts on redirected requests

**URL:** https://community.gatling.io/t/getting-url-parts-on-redirected-requests/1301
**Category:** Gatling (Open-Source)
**Created:** [August 19, 2014, 5:30pm UTC](https://community.gatling.io/t/getting-url-parts-on-redirected-requests/1301 "2014-08-19T17:30:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Galen\_Fisher](https://avatars.discourse-cdn.com/v4/letter/g/dc4da7/32.png) [@Galen\_Fisher](https://community.gatling.io/u/Galen_Fisher)
#### Post date: [August 19, 2014, 5:30pm UTC](https://community.gatling.io/t/getting-url-parts-on-redirected-requests/1301/1 "2014-08-19T17:30:13Z")

</div>

Hey guys. I’ve got a portion of my application I’m trying to stress test and it generates a unique key each time as part of the URL to represent the state of a user’s application process. The application unfortunately contains a number of redirects so I’m stumped how to get the URL parts I need. Disabling redirects is going to make the tests difficult to maintain I think. There are a LOT. For the pages I’m testing once all the redirects are done there’s no “Location” in the response so it appears as my headerRegex call is failing to get anything

My relevant Scala looks like this now for debugging which I adapted from the groups list here:

.exec(http(“request\_8”)  
.get(“”“/path/to/applyTo/236"”“)  
.headers(headers\_1)  
.check(  
headerRegex(“Location”, “””.+“”").find.saveAs(“redirectURL”)  
)  
)  
.exec(session =\> { println(session(“redirectURL”).as[Seq[String]]); session })

Here are some fun logs with trace enabled I’ve paired them down:

12:22:15.727 [INFO] i.g.h.a.HttpRequestAction - Sending request ‘request\_8’: scenario ‘Test Scenario’, userId #0  
12:22:16.298 [TRACE] i.g.h.a.AsyncHandlerActor -

> # Request: request\_8: OK
> 
> # Session: Session(Test Scenario,0,Map(gatling.http.cookies → CookieStore=Map([//release12.localhost](https://release12.localhost) → List(…))),1408465310071,36,List(),List(OK),List(),List())
> 
> HTTP request:  
> GET [http://release12.localhost/path/to/applyTo/236](http://release12.localhost/path/to/applyTo/236)  
> headers=  
> …  
> User-Agent: [Mozilla/5.0 (X11; Ubuntu; Linux x86\_64; rv:30.0) Gecko/20100101 Firefox/30.0]
> 
> =========================  
> HTTP response:  
> status=  
> 303 See Other  
> headers=  
> Date: [Tue, 19 Aug 2014 16:22:15 GMT]  
> …  
> Location: [[http://release12.localhost/path/to/Application\_53f363ed80ba8](http://release12.localhost/path/to/Application_53f363ed80ba8)]  
> Content-Length: [0]  
> …  
> Content-Type: [text/html; charset=UTF-8]

12:22:16.864 [WARN] i.g.h.a.AsyncHandlerActor - **Request ‘request\_8 Redirect 1’ failed : headerRegex((Location,.+)).exists() didn’t match:** found nothing  
12:22:16.865 [TRACE] i.g.h.a.AsyncHandlerActor -

> > > > > > > > > > > > > > > > > > > > > > > > > >

Request:  
request\_8 Redirect 1: KO headerRegex((Location,.+)).exists() didn’t match: found nothing

---

<div class="post-metadata">

### Author: ![Galen\_Fisher](https://avatars.discourse-cdn.com/v4/letter/g/dc4da7/32.png) [@Galen\_Fisher](https://community.gatling.io/u/Galen_Fisher)
#### Post date: [August 20, 2014, 5:22pm UTC](https://community.gatling.io/t/getting-url-parts-on-redirected-requests/1301/2 "2014-08-20T17:22:33Z")

</div>

In case anyone is interested or for future posterity, I solved this by doing the following. I’m not sure if this is the best route but it works.

.exec(http(“request\_8”)  
.get("""/path/to/applyTo/236""")  
.check(currentLocation.transform(s =\> {  
val locationRegex = “”"(?\<=/path/to/Application\_)(\d\w+)""".r  
val locationKey = locationRegex findFirstIn s  
locationKey.get  
}).saveAs(“redirectURL”))  
)

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [August 23, 2014, 11:58pm UTC](https://community.gatling.io/t/getting-url-parts-on-redirected-requests/1301/3 "2014-08-23T23:58:01Z")

</div>

Yes, that’s the way to go.

Just one thing: you really should declare your regex OUTSIDE the closure, otherwise it gets compiled every time it’s executed.
