org.http4s.multipart
This package is the start of a multipart implementation for http4s. It is still deficient in a few ways:
- All encoding is chunked transfers, except for entities small enough to fit into the blaze buffer. This irritates some server implementations.
- When decoding, chunks are kept in memory. Large ones should be buffered to a temp file.
- It's a bit handwavy around character sets. Things probably go horribly wrong if you're not UTF-8.
- This module is lightly tested, and its API should be considered experimental.
Enter this package at your own risk, but we'd love the feedback.
Attributes
Members list
Type members
Classlikes
Attributes
- Companion
- object
- Source
- Boundary.scala
- Supertypes
Attributes
- Companion
- class
- Source
- Boundary.scala
- Supertypes
- Self type
-
Boundary.type
Create a new multipart from a vector of parts and a boundary.
Create a new multipart from a vector of parts and a boundary.
To create Multipart values from a generated boundary, see the Multiparts algebra.
Attributes
- Source
- Multipart.scala
- Supertypes
A low-level multipart-parsing pipe.
A low-level multipart-parsing pipe. Most end users will prefer EntityDecoder[Multipart].
Attributes
- Source
- MultipartParser.scala
- Supertypes
- Self type
-
MultipartParser.type
Composable logic for receiving data from multipart/form-data request bodies.
Composable logic for receiving data from multipart/form-data request bodies.
A MultipartReceiver works by delegating to a PartReceiver for each Part in the body. It may or may not use the same PartReceiver for each Part. The results from each Part are collected to a List[Partial] (where Partial is an abstract type significant to the specific MultipartReceiver instance), then post-processed into a final result of type A.
For the simplest use-cases, MultipartReceiver.auto will suffice. However, MultipartReceiver is designed for customizability and control over how each Part is handled as its data is received.
MultipartReceiver is Applicative in type F, allowing receiver logic to be defined for one field at a time, then compose the logic for each field into a single receiver. You can define single-field receivers with the DSL starting at MultipartReceiver.at. For example:
case class Nominee(name: String, age: Int, accolades: List[String], photo: fs2.io.file.Path)
val nomineeReceiver: MultipartReceiver[IO, Nominee] = (
MultipartReceiver.at("name", PartReceiver.bodyText[IO].withSizeLimit(256)).once,
MultipartReceiver.at("age", PartReceiver.decode[IO, Int].withSizeLimit(8)).once,
MultipartReceiver.at("accolades", PartReceiver.bodyText[IO].withSizeLimit(1024)).asList,
MultipartReceiver.at("photo", PartReceiver.toTempFile[IO].withSizeLimit(2 * 1024 * 1024)).once,
).mapN(Nominee.apply)
val nomineeDecoderRes: Resource[IO, EntityDecoder[IO, Nominee]] =
MultipartDecoder.fromReceiver(nomineeReceiver)
When used to construct an EntityDecoder via MultipartDecoder.fromReceiver, the result is expressed as a Resource. This allows the MultipartReceiver to allocate resources (like temp files) whose lifetimes are tied to the decoder resource. I.e.
nomineeDecoderRes.use { nomineeDecoder =>
nomineeDecoder
.decode(request, strict = false) // <- may allocate temp files
} // <- temp files deleted on release
Type parameters
- A
-
The result type
- F
-
The effect type
Attributes
- Companion
- object
- Source
- MultipartReceiver.scala
- Supertypes
- Self type
-
Attributes
- Companion
- trait
- Source
- MultipartReceiver.scala
- Supertypes
- Self type
-
MultipartReceiver.type
An algebra for creating multipart values and boundaries.
An algebra for creating multipart values and boundaries.
A single instance may be shared by the entire application.
Attributes
- Companion
- object
- Source
- Multiparts.scala
- Supertypes
Attributes
- Companion
- trait
- Source
- Multiparts.scala
- Supertypes
- Self type
-
Multiparts.type
Attributes
- Companion
- object
- Source
- Part.scala
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Media[F]class Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Source
- Part.scala
- Supertypes
- Self type
-
Part.type
Represents the decoding process of a single "part" in a multipart/form-data message.
Represents the decoding process of a single "part" in a multipart/form-data message.
Used in conjunction with MultipartReceiver and MultipartDecoder.fromReceiver to create robust EntityDecoders with fail-fast behavior.
Attributes
- Companion
- object
- Source
- PartReceiver.scala
- Supertypes
Attributes
- Companion
- trait
- Source
- PartReceiver.scala
- Supertypes
- Self type
-
PartReceiver.type
Generic representation of typical Multipart Part bodies, as either a string or a file path.
Generic representation of typical Multipart Part bodies, as either a string or a file path. Produced by MultipartReceiver.auto.
Similar to Part, but with less Header-oriented detail, and a clearer distinction between in-memory data vs on-disk data.
Attributes
- Companion
- object
- Source
- PartValue.scala
- Supertypes
- Known subtypes
Attributes
- Companion
- trait
- Source
- PartValue.scala
- Supertypes
- Self type
-
PartValue.type