Last active
November 25, 2018 07:59
-
-
Save adamw/587ca71801b7cfd3b57a6974bf2c9218 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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