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.

Support Multipart Response

See original GitHub issue

Receiving the following headers and body as a response, I’m not able to parse the parts. Exception thrown:

org.http4k.multipart.ParseError: no name for part

Headers received:

HTTP/1.1 200 OK
Date: Fri, 13 Dec 2019 09:10:19 GMT
Content-Type: multipart/form-data; boundary=ofz0Oi4n1E68F6IC91sf36bcHAX5sy
Transfer-Encoding: chunked
Connection: keep-alive
Y-Tro-Optapi-Requestid: ofz0Oi4n1E68F6IC91sf36bcHAX5sy
Strict-Transport-Security: max-age=15724800; includeSubDomains
Server: trorisalve

Body received:

--ofz0Oi4n1E68F6IC91sf36bcHAX5sy
Content-Disposition: attachment; name=values
Content-Type: text/csv

A,B,C
932,059A,2019-11-25
933,96A,2019-11-25


--ofz0Oi4n1E68F6IC91sf36bcHAX5sy
Content-Disposition: attachment; name=logs
Content-Type: application/x-ndjson

{"level":"info","time":1576656181033,"message":"Starting, build 01e3342d 2019-12-11 12:03:51 +0100 (master) with run id ","pid":152568,"thread_id":152568}
{"level":"info","time":1576656181033,"message":"Reading input from stdin...","pid":152568,"thread_id":152568}

--ofz0Oi4n1E68F6IC91sf36bcHAX5sy--

The exception is thrown in StreamingMultipartFormsPart.kt:

val contentDisposition = ParameterParser().parse(headers["Content-Disposition"], ';')
val fieldName = (if (contentDisposition.containsKey("attachment")) mixedName else trim(contentDisposition["name"]))
                ?: throw ParseError("no name for part")

mixedName is null, and should probably only be used within a multipart/mixed context if I read the code correctly?

Call site code:

val client = ApacheClient()
val response = client(request)
val multipart = MultipartFormBody.from(response)
println("multipart boundary = ${multipart.boundary}")

http4k version: 3.196.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alphahocommented, May 25, 2020

I see. Then I will try to come up with something similar to the existing multipart form data setup.

0reactions
daviddentoncommented, May 24, 2020

I don’t see the hack as a viable forward option at all. I also know that the current implementation of multipart form data is pretty complicated.

At the very least I’d probably duplicate the required logic to start with and we can see where we go from there. It might be that we can tease out some common code a bit later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multipart HTTP response - Stack Overflow
You can serve the response as multipart/form-data and use Response.formData() to read response at client fetch("/path/to/server", ...
Read more >
Parsing multipart/mixed response in Spring Webclient - Medium
It is a http format which lets you attach multiple files to the request body of an REST API. What is uncommon, however,...
Read more >
Multipart response - Microsoft Q&A
Browsers don't support multipart responses. You can use JavaScript to to make an Ajax call, but you will need to write code to...
Read more >
Multipart Requests - Swagger
Multipart requests combine one or more sets of data into a single body, separated by boundaries. You typically use these requests for file...
Read more >
Error while handling multipart request and response in Web ...
A Web Service Proxy (WS-Proxy) was created which was expected to accept an XML request with multipart and return a Non-XML multipart as...
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