Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating HTTP multipart response in Netty

I'm creating a REST service which returns some computed values back to the client. Netty is very performant at doing this. However, there are cases, when I need to return multiple values for the same URI (query). Here are the approaches we considered: i) Package all the values into a custom format which the clients must know how to decode. ii) Use MIME multipart support.

Approach ii) is much cleaner and is in line with the REST methodology. Is it just me, or I find it hard to figure out how to do this in Netty ?

I went through the File Upload example cited in the Netty documentation. But I cannot figure out how to do the same for in-memory data ?

Any leads / ideas ?

like image 677
user2171209 Avatar asked Jun 26 '26 12:06

user2171209


1 Answers

I know it's an old question, but if still needed: If I understand, you want to send multiple values with the same name back as a MIME multipart content, right ?

  • First create your HttpDataFactory (probably setting useDisk to False if you want to saty in memory)
  • Then create your HttpPostRequestEncoder with multipart set to true
  • and add as many as you want attribute using encoder.addBodyAttribute(name, value) where value is the only one changing

That should do what you want?

like image 91
Frederic Brégier Avatar answered Jun 30 '26 13:06

Frederic Brégier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!