title: How to set `Set-Cookie` header in HttpResponse in Akka Scala?
body: <p>I have the following route in my app:</p>
  
  <pre><code>val myRoute = Route { context =&gt;
  
          val handler = Source.single(getRequest(context))
            .via(flow(server, port))
            .runWith(Sink.head).flatMap { r =&gt;
  
            // Add cookie to response depending on certain preconditions
  
           context.complete(r)
  
        }
  
  }
  </code></pre>
  
  <p>My problem is that I can't use the out-of-the-box <a href="http://doc.akka.io/docs/akka/2.4.3/scala/http/routing-dsl/directives/cookie-directives/setCookie.html" rel="nofollow noreferrer"><code>setCookie</code></a> method (or can I?) because I am inside a route, so I will get a type error. I thought about manually adding a header element to the <code>HttpResponse</code> (in the example above <code>r</code>), but that is quite cumbersome. </p>
  
  <p>Any ideas how I can easily add the <code>Set-Cookie</code> header element?</p>