Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
= httpx: make multipart unmarshaller strip Content-Type header, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
sirthias committed Oct 7, 2014
1 parent f9309bb commit b56619a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ trait FormDataUnmarshallers {
.getOrElse(ContentType(`text/plain`, defaultCharset)) // RFC 2046 section 5.1
val outputStream = new ByteArrayOutputStream
FileUtils.copyAll(part.readOnce(), outputStream)
BodyPart(HttpEntity(contentType, outputStream.toByteArray), headers)
BodyPart(HttpEntity(contentType, outputStream.toByteArray), headers.filterNot(_.isInstanceOf[`Content-Type`]))
}(collection.breakOut)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class FormDataUnmarshallersSpec extends Specification {
Seq(
BodyPart(
HttpEntity(ContentTypes.`text/plain(UTF-8)`, "test@there.com"),
List(
`Content-Disposition`("form-data", Map("name" -> "email")),
`Content-Type`(ContentTypes.`text/plain(UTF-8)`)))))
List(`Content-Disposition`("form-data", Map("name" -> "email"))))))
}
}
"correctly unmarshal multipart content with two different parts" in {
Expand All @@ -67,9 +65,7 @@ class FormDataUnmarshallersSpec extends Specification {
BodyPart(HttpEntity(ContentTypes.`text/plain(UTF-8)`, "first part, with a trailing newline\r\n")),
BodyPart(
HttpEntity(`application/octet-stream`, "filecontent"),
List(
RawHeader("Content-Transfer-Encoding", "binary"),
`Content-Type`(ContentTypes.`application/octet-stream`)))))
List(RawHeader("Content-Transfer-Encoding", "binary")))))
}
}
"reject illegal multipart content" in {
Expand All @@ -96,10 +92,10 @@ class FormDataUnmarshallersSpec extends Specification {
Seq(
BodyPart(
HttpEntity(ContentTypes.`text/plain`, "ABC"),
List(`Content-Type`(ContentTypes.`text/plain`), `Content-Range`(ContentRange(0, 2, 26)))),
List(`Content-Range`(ContentRange(0, 2, 26)))),
BodyPart(
HttpEntity(ContentTypes.`text/plain`, "XYZ"),
List(`Content-Type`(ContentTypes.`text/plain`), `Content-Range`(ContentRange(23, 25, 26))))))
List(`Content-Range`(ContentRange(23, 25, 26))))))
}
}
}
Expand Down Expand Up @@ -159,6 +155,13 @@ class FormDataUnmarshallersSpec extends Specification {
|--XYZABC--""".stripMargin).as[MultipartFormData]
msg === "Illegal multipart/form-data content: unnamed body part (no Content-Disposition header or no 'name' parameter)"
}

"round-trip a non-empty multipart message" in {
val parts = MultipartFormData(Map("message" -> BodyPart(HttpEntity(ContentTypes.`text/plain(UTF-8)`, "x"))))
val entity = spray.httpx.marshalling.marshalUnsafe(parts)
val roundtrippedParts = entity.as[MultipartFormData].right.get
roundtrippedParts === parts
}
}

"The UrlEncodedFormDataUnmarshaller" should {
Expand Down

0 comments on commit b56619a

Please sign in to comment.