question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multipart part's Content-Disposition with non-ascii filename fails to parse

See original GitHub issue

Using http4s 0.23.7.

Given the a simple service which parses the body as a multipart, which:

import cats.effect._
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.dsl.io._
import org.http4s.headers.`Content-Disposition`
import org.http4s.server.Router
import org.http4s.{EntityDecoder, HttpRoutes, multipart}

import scala.concurrent.ExecutionContext

object Test2 extends IOApp {
  val service: HttpRoutes[IO] = HttpRoutes.of[IO] {
    case r @ POST -> Root / "file" =>
      implicitly[EntityDecoder[IO, multipart.Multipart[IO]]]
        .decode(r, strict = false)
        .value
        .flatMap {
          case Left(_) => BadRequest()
          case Right(mp) =>
            println("Got parts: " + mp.parts)
            mp.parts.foreach { part =>
              println("Part name: " + part.name)
              println("Part content disposition: " + part.headers.getWithWarnings[`Content-Disposition`])
            }
            Ok()
        }
    case _ =>
      BadRequest()
  }

  implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global

  override def run(args: List[String]): IO[ExitCode] = {
    BlazeServerBuilder[IO]
      .withExecutionContext(ec)
      .bindHttp(8080, "localhost")
      .withHttpApp(Router("/" -> service).orNotFound)
      .resource
      .use { _ => IO.never }
      .as(ExitCode.Success)
  }
}

And invocation:

curl -v -X 'POST' 'http://localhost:8080/file' -H 'accept: text/plain' -H 'Content-Type: multipart/form-data' -F 'file=@中文文件名.json;type=application/json'

The result on stdout is:

Got parts: Vector(Part(Headers(Content-Disposition: form-data; name="file"; filename="中文文件名.json", Content-Type: application/json),Stream(..)))
Part name: None
Part content disposition: Some(Left(NonEmptyList(org.http4s.ParseFailure: Invalid Content-Disposition header: Error(34,NonEmptyList(InRange(34,","))))))

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
armanbilgecommented, Sep 27, 2022
1reaction
danichegcommented, Sep 24, 2022

@counter2015 some time ago, I proposed these changes you described – https://github.com/http4s/http4s/pull/6475. But we have ended up with this https://github.com/http4s/http4s/pull/6485.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Any way to make Android's default browser recognize non ...
Any way to make Android's default browser recognize non-ASCII filenames in "Content-Disposition: attachment" downloads? ... First of all, I'm pretty sure this is ......
Read more >
Content-Disposition - HTTP - MDN Web Docs
A multipart/form-data body requires a Content-Disposition header to provide information for each subpart of the form (e.g. for every form field ...
Read more >
HTTP/1.1: Appendices
When an HTTP 206 (Partial Content) response message includes the content of multiple ranges (a response to a request for multiple non-overlapping ranges),...
Read more >
MimeBodyPart (Java EE 6 ) - Oracle Help Center
MIME allows non ASCII characters to be present in certain portions of certain headers, ... The DataHandler object representing this Part's content.
Read more >
Package jakarta.mail.internet
By default, strict parsing of address headers is done. If this property is set to ... The MIME spec does not allow multipart...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found