Could you guys tell me why following form of extraction works for both multipart/form-data
and x-www-form-urlencoded
requests
formFields("firstName"?, "age2"?, "sex", "vip"?) {
(firstName : Option[String], age2, sex, vip) =>
complete(firstName + "." + age2 + "." + sex + "." + vip)
}
but this, seemingly equal, version of code
formFields('firstName :: ("age2".as[Int]) :: ('sex?) :: ("VIP" ? false) :: HNil) {
(firstName : String, age2 : Int, sex : Option[String], vip : Boolean) =>
complete(firstName + "." + age2 + "." + sex + "." + vip)
}
doesn't work when request is multipart/form-data
encoded.
Server returns following error:
There was a problem with the requests Content-Type:
Field 'age2' can only be read from 'application/x-www-form-urlencoded' form content
I see a call-stack to spray.httpx.unmarshalling.FormField.fail
but my Scala skills are not strong enough to decipher it.