Skip to content

Instantly share code, notes, and snippets.

@is
Created March 21, 2013 16:36
Show Gist options
  • Save is/5214489 to your computer and use it in GitHub Desktop.
Save is/5214489 to your computer and use it in GitHub Desktop.
Set X-Transmission-Session-Id when return code == 409
// If Code == 409, Set X-Transmission-Session-Id and retry.
def httpX[T](x: Handler[T]): HttpPackage[T] = {
val hand = x.copy(request = x.request <:< Map("X-Transmission-Session-Id" -> sessId))
var is409: Boolean = false
val r = http.x(hand.copy(
block = { (code, res, ent) =>
if (code != 409)
hand.block(code, res, ent)
else {
val st = Map.empty[String, Set[String]].withDefaultValue(Set.empty)
sessId = ((st /: res.getAllHeaders()) { (m, h) =>
m + (h.getName -> (m(h.getName) + h.getValue))
}).get("X-Transmission-Session-Id").get.head
is409 = true
hand.block(code, res, ent)
}
}))
if (!is409)
r
else
httpX(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment