Permalink
Browse files

! http(x): rename BodyPart.getName -> BodyPart.name, add BodyPart.dis…

…positionParameterValue
  • Loading branch information...
jrudolph committed Sep 26, 2013
1 parent 0339833 commit 9d275592daf7fa47c23d714035fe0121c840a10d
@@ -42,12 +42,12 @@ object FormData {
*/
case class MultipartFormData(fields: Seq[BodyPart]) extends HttpForm {
type FieldType = BodyPart
- def get(partName: String): Option[BodyPart] = fields.find(_.getName == Some(partName))
+ def get(partName: String): Option[BodyPart] = fields.find(_.name.exists(_ == partName))
}
object MultipartFormData {
val Empty = MultipartFormData(Seq.empty)
def apply(fields: Map[String, BodyPart]): MultipartFormData = this(fields.map {
case (key, value) value.copy(headers = `Content-Disposition`("form-data", Map("name" -> key)) +: value.headers)
}.toSeq)
-}
+}
@@ -30,9 +30,11 @@ object MultipartContent {
* Model for one part of a multipart message.
*/
case class BodyPart(entity: HttpEntity, headers: Seq[HttpHeader] = Nil) {
- def getNameOrEmpty: String = getName.getOrElse("")
- def getName: Option[String] = headers.collectFirst {
- case HttpHeaders.`Content-Disposition`("form-data", parameters) if parameters.contains("name")
- parameters("name")
- }
+ val name: Option[String] = dispositionParameterValue("name")
+
+ def dispositionParameterValue(parameter: String): Option[String] =
+ headers.collectFirst {
+ case HttpHeaders.`Content-Disposition`("form-data", parameters) if parameters.contains(parameter)
+ parameters(parameter)
+ }
}
@@ -29,9 +29,9 @@ object FormFieldExtractor {
type Field = UrlEncodedFormField
def field(name: String) = new UrlEncodedFormField(name, fields.find(_._1 == name).map(_._2))
}
- case MultipartFormData(fields) new FormFieldExtractor {
+ case multiPartData: MultipartFormData new FormFieldExtractor {
type Field = MultipartFormField
- def field(name: String) = new MultipartFormField(name, fields.find(_.getName == Some(name)))
+ def field(name: String) = new MultipartFormField(name, multiPartData.get(name))
}
}
}
@@ -101,4 +101,4 @@ private[unmarshalling] abstract class FfcLowerPrioImplicits2 {
lazy val urlEncodedFieldConverter = ffc.urlEncodedFieldConverter.map(Deserializer.liftToTargetOption(_))
lazy val multipartFieldConverter = ffc.multipartFieldConverter.map(Deserializer.liftToTargetOption(_))
}
-}
+}
@@ -103,7 +103,7 @@ class FormDataUnmarshallersSpec extends Specification {
|
|filecontent
|--XYZABC--""".stripMargin).as[MultipartFormData].get.fields.map {
- case part @ BodyPart(entity, _) part.getName.get + ": " + entity.as[String].get
+ case part @ BodyPart(entity, _) part.name.get + ": " + entity.as[String].get
}.mkString("|") === "email: test@there.com|userfile: filecontent"
}
"reject illegal multipart content" in {

0 comments on commit 9d27559

Please sign in to comment.