Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active November 25, 2018 07:59
Show Gist options
  • Save adamw/587ca71801b7cfd3b57a6974bf2c9218 to your computer and use it in GitHub Desktop.
Save adamw/587ca71801b7cfd3b57a6974bf2c9218 to your computer and use it in GitHub Desktop.
class SetCorrelationIdBackend(delegate: SttpBackend[Task, Nothing])
extends SttpBackend[Task, Nothing] {
override def send[T](request: sttp.Request[T, Nothing]): Task[Response[T]] = {
// suspending the calculation of the correlation id until the request
// send is evaluated
Task {
CorrelationId() match {
case Some(cid) => request.header(CorrelationIdHeader, cid)
case None => request
}
}.flatMap(delegate.send)
}
override def close(): Unit = delegate.close()
override def responseMonad: MonadError[Task] = delegate.responseMonad
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment