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

final case class Boundary(value: String) extends AnyVal

Attributes

Companion
object
Source
Boundary.scala
Supertypes
trait Serializable
trait Product
trait Equals
class AnyVal
trait Matchable
class Any
Show all
object Boundary

Attributes

Companion
class
Source
Boundary.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Boundary.type
final case class Multipart[+F[_]](parts: Vector[Part[F]], boundary: Boundary)

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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

A low-level multipart-parsing pipe.

A low-level multipart-parsing pipe. Most end users will prefer EntityDecoder[Multipart].

Attributes

Source
MultipartParser.scala
Supertypes
class Object
trait Matchable
class Any
Self type
trait MultipartReceiver[F[_], A]

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
class Object
trait Matchable
class Any
Self type

Attributes

Companion
trait
Source
MultipartReceiver.scala
Supertypes
class Object
trait Matchable
class Any
Self type
trait Multiparts[F[_]]

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
class Object
trait Matchable
class Any
object Multiparts

Attributes

Companion
trait
Source
Multiparts.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Multiparts.type
final case class Part[+F[_]](headers: Headers, entity: Entity[F]) extends Media[F]

Attributes

Companion
object
Source
Part.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Media[F]
class Object
trait Matchable
class Any
Show all
object Part

Attributes

Companion
class
Source
Part.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Part.type
trait PartReceiver[F[_], A]

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
class Object
trait Matchable
class Any
object PartReceiver

Attributes

Companion
trait
Source
PartReceiver.scala
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait PartValue

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
class Object
trait Matchable
class Any
Known subtypes
class OfFile
class OfString
object PartValue

Attributes

Companion
trait
Source
PartValue.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
PartValue.type