In short, the problem is that your code runs at route-building time not when the request is actually handled.
This document explain it in longer form: http://spray.io/documentation/spray-routing/advanced-topics/understanding-dsl-structure/
If you look on the mailing list you will find lots of threads about this exact problem which should help you further.
HTH