Skip to content

Instantly share code, notes, and snippets.

@magro
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magro/19100fe8ca16b5711b85 to your computer and use it in GitHub Desktop.
Save magro/19100fe8ca16b5711b85 to your computer and use it in GitHub Desktop.
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