Last active
August 29, 2015 14:20
-
-
Save jonoabroad/a6465efe48b2825cc28a to your computer and use it in GitHub Desktop.
Suggested implementation of MultiPart for http4s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final case class Name(value:String) extends AnyVal | |
sealed trait Part | |
final case class FormData(name:Name, | |
content: Entity, | |
contentType: Option[ContentType] = None ) extends Part | |
final case class MultiPart(parts: Seq[Part]) { | |
def boundary = ??? // leaving out implementation for clarity | |
def header = ??? // leaving out implementation for clarity | |
} | |
/* | |
E.g of creating a simple multipart | |
*/ | |
val txtToEntity: String => Entity = ??? | |
val entity = txtToEntity("I Am a textual entity.") | |
val field1 = FormData("field1", entity) | |
val multiPart = MultiPart(List(field1)) | |
/* | |
Usuage will depend on whether changes to EntityEncoder are possible. | |
Without changes to EntityEncoder : | |
*/ | |
request.withHeaders(multiPart.headers).withBody(multiPart) | |
/* | |
With changes to EntityEncoder : | |
*/ | |
request.withBody(multiPart) | |
/* | |
* The reason to change EntityEncoder, is that the request headers and entity body are dependent | |
* on the Multipart boundary, which is currently only available to the 'toEntity' method. | |
* | |
*/ | |
Makes sense. I'll try and get a PR to you for the current work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allowing the toEntity method to generate headers seams reasonable, in theory. I think that would be a parallel or followup issue/PR.