Created
March 21, 2013 16:36
-
-
Save is/5214489 to your computer and use it in GitHub Desktop.
Set X-Transmission-Session-Id when return code == 409
This file contains 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
// 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