Created
August 9, 2012 11:53
-
-
Save arosh/3303574 to your computer and use it in GitHub Desktop.
extractSessionID
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
/** | |
* headerからSessionIDを抽出する | |
*/ | |
def extractSessionID(header: Map[String, Set[String]]): Option[String] = { | |
val regex = """^JSESSIONID=(\w+);.+$""".r | |
val r = header.get("Set-Cookie") flatMap { cookie => | |
cookie collect { | |
case regex(id) => id | |
} headOption | |
} | |
r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
collectしてからheadOptionするなら、collectFirstっていう便利なものが
forでも書けるけど余計な変数増えるし、あまり意味ない気がする