Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing final boundary for empty multipart entities #1257

Closed
arnohaase opened this issue Jun 30, 2017 · 4 comments
Closed

Missing final boundary for empty multipart entities #1257

arnohaase opened this issue Jun 30, 2017 · 4 comments
Labels
3 - in progress Someone is working on this ticket t:core Issues related to the akka-http-core module
Milestone

Comments

@arnohaase
Copy link

arnohaase commented Jun 30, 2017

When rendering a multipart entity with no parts, BodyPartRenderer does not write the final boundary. This results in an entity that Akka HTTP can not parse:

val entity = Multipart.General
  .Strict(MediaTypes.`multipart/mixed`, Vector.empty)
  .toEntity("asdf")

val um = MultipartUnmarshallers.defaultMultipartGeneralUnmarshaller
val unmarshalled = Await.result(um(entity), 10.seconds) // triggers an exception

println (unmarshalled)

The suggested fix is to move renderFinalBoundary out of the if block in class BodyPartRenderer.

  def strict(parts: immutable.Seq[Multipart.BodyPart.Strict], boundary: String,
             partHeadersSizeHint: Int, log: LoggingAdapter): ByteString = {
    val r = new ByteStringRendering(partHeadersSizeHint)
    if (parts.nonEmpty) {
      for (part ← parts) {
        renderBoundary(r, boundary, suppressInitialCrLf = part eq parts.head)
        renderEntityContentType(r, part.entity)
        renderHeaders(r, part.headers, log)
        r ~~ part.entity.data
      }
      // <--- renderFinalBoundary removed here
    }
    renderFinalBoundary(r, boundary)   // <--- ... and moved here
    r.get
  }
@arnohaase
Copy link
Author

arnohaase commented Jun 30, 2017

This being my first bug report, I am unsure as to the best procedure. Should I create a pull request?

@raboof
Copy link
Member

raboof commented Jun 30, 2017

Hi Arno, Welcome!

Yes, a pull request would be great! You can read more about our contribution process in CONTRIBUTING.md - it's quite a bit of text, but don't worry, most of it is pretty light once you get the hang of it. It'd be great if you could reproduce the problem in a unit test. If you get stuck anywhere feel free to drop by on gitter at https://gitter.im/akka/dev - we're always happy to help.

@arnohaase
Copy link
Author

Thanks - I'll do that over the weekend.

arnohaase pushed a commit to arnohaase/akka-http that referenced this issue Jun 30, 2017
@jrudolph jrudolph added 3 - in progress Someone is working on this ticket t:core Issues related to the akka-http-core module labels Jul 17, 2017
jrudolph added a commit that referenced this issue Jul 26, 2017
Add final boundary for multipart entities with no parts #1257
@jrudolph jrudolph added this to the 10.0.10 milestone Jul 26, 2017
@jrudolph
Copy link
Member

Fixed by #1260.

@jrudolph jrudolph modified the milestone: 10.0.10 Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - in progress Someone is working on this ticket t:core Issues related to the akka-http-core module
Projects
None yet
Development

No branches or pull requests

3 participants