Getting value from session to use in non gatling DSL function

I want to do something like the following where I can extract the value from my session and pass it to my own function to generate the correct headers from this simulation. However the code below does not work as expected since the http request is never executed.
How can I do what im trying to du using gatling?

def post()(implicit h: String => Map[String, String]) =
  exec(Body.*requestBodyGenerator*).
    exec(session => {
val id = session("personId").asOption[String].getOrElse(defaultId)
      http("GetID").
        post("/getid").
        body(StringBody("${body}")).
        asJSON.
        headers(h(label)).
        check(responseTimeInMillis)
session
    })

label should be id in function call but this is not the problem, this is only a result of me editing the post.

You get it wrong.
Instead of trying to generate a RequestBuilder in a function (which doesn’t work as explained in the doc), why don’t you pass a function to headers?

You mean somthing like this? This actually works but i loose the ability to use getOrElse to set a default value if no personId is added in the session.

def post()(implicit h: String => Map[String, String]) =
  exec(Body.*requestBodyGenerator*).
    exec(session => {
      http("GetID").
        post("/getid").
        body(StringBody("${body}")).
        asJSON.
        headers(h("${personId}")).
        check(responseTimeInMillis)
session
    })

You mean somthing like this?

No I don't.

http://gatling.io/docs/2.2.3/advanced_tutorial.html#step-05-check-and-failure-management

Still not getting it, I have tried this but headers does not support functions to be sent to it…

def post()(implicit h: String => Map[String, String]) =
  exec(Body.*requestBodyGenerator*).
    exec(session => {
      http("GetID").
        post("/getid").
        body(StringBody("${body}")).
        asJSON.
        headers(session => Map("" -> "").
        check(responseTimeInMillis)
session
    })