Last active
August 29, 2015 14:01
-
-
Save magro/19100fe8ca16b5711b85 to your computer and use it in GitHub Desktop.
Playframework BodyParsers multipartParser (source: https://github.com/playframework/playframework/blob/92078f9cc751a5c19117dede18c7ca63aca73347/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala#L615)
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
def multipartParser[A](partHandler: Map[String, String] => Iteratee[Array[Byte], A]): | |
BodyParser[Seq[A]] = parse.using { request => | |
val maybeBoundary = for { | |
mt <- request.mediaType | |
(_, value) <- mt.parameters.find(_._1.equalsIgnoreCase("boundary")) | |
boundary <- value | |
} yield ("\r\n--" + boundary).getBytes("utf-8") | |
maybeBoundary.map { boundary => | |
BodyParser { request => | |
// implementation with some iteratee fu | |
} | |
}.getOrElse(parse.error(createBadResult("Missing boundary header")(request))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment