Problems extracting a header

Hi,

I’m having issues extracting a header into a variable, this is the response:

HTTP response:
status=
303 See Other
headers=
Location: [http://my_website.com/page2#access_token=my_token]
Server: [Apache-Coyote/1.1]
Content-Length: [235]
Connection: [keep-alive]

And this is a fragment of my scenario:

.exec(http(“Get token”)
.get("https://my_website/page1)
.check(status.is(303))

.check(header(“Server”).saveAs(“server”)))

Now, If I try to use “${server}” after that, I get this error:

No attribute named ‘server’ is defined.

What I really need is extract the access_token from the url fragment. I tried something like this (which also didn’t work):

.check(headerRegex(HttpHeaderNames.Location, “access_token=([^&]+)”).saveAs(“accessToken”)))

Any help will be greatly appreciated!

Juan Pablo

Did you disable redirect following? Otherwise, you’re checking the final landing page.
http://gatling.io/docs/2.0.0-RC5/http/http_protocol.html?highlight=disablefollowredirect#follow-redirects

What you’re looking for is “currentLocationRegex”
http://gatling.io/docs/2.0.0-RC5/http/http_check.html#page-location

Thanks for you help Stéphane,

If I use disablefollowredirect I get an error:

status.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 303

I must be doing something else wrong, because even after using currentLocationRegex

.exec(http(“Get token”)
.get(“https://my_website/page1”)
.check(status.is(303))
.check(currentLocationRegex(“access_token=([^&]+)”).saveAs(“accessToken”)))

I still get No attribute named ‘accessToken’ is defined if I try to use it later.

Thanks for your help Stéphane,

If I use .disableFollowRedirect, I get these error:

status.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 303

It looks like the code is checking that there are no redirects (which in my case I cannot avoid).

I must be doing something wrong, because I still get the error:

No attribute named ‘accessToken’ is defined

on this code:

.exec(http(“Get token”)
.get(“https://my_website/page1”)
.check(status.is(303))
.check(currentLocationRegex(“access_token=([^&]+)”).saveAs(“accessToken”)))

.pause(2)
.exec(http(“test”).get("/url?${accessToken}"))

Could you share what you’re doing exactly with disableFollowRedirect? I works as expected for me.

Then, you didn’t get it right:

  • if you’re using disableFollowRedirect, then your landing page will be your 303 response with a Location header
  • OTHERWISE, your landing page will be what your Location header points to