Multipart part's Content-Disposition with non-ascii filename fails to parse
See original GitHub issueUsing 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:
- Created 2 years ago
- Comments:11 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@counter2015 yes, it was first released in 0.23.13. https://github.com/http4s/http4s/releases/tag/v0.23.13
@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.