Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return GZIP responses with Spring Webflux?

Let's say I have a very simple HTTP endpoint using Spring Webflux:

@GetMapping
fun greeting(@RequestParam("msg") val message : String) = Mono.just(Greeting(message))

where Greeting is a simple DTO serialized as JSON. How can I instruct Spring Webflux to return the response compressed as GZIP? I'm using the Netty implementation if that matters.

like image 679
Johan Avatar asked Nov 21 '25 14:11

Johan


2 Answers

What you are looking for is server compression properties

server.compression.enabled=true
server.compression.min-response-size=1024
like image 148
Alexander Pankin Avatar answered Nov 24 '25 09:11

Alexander Pankin


Adding to above-accepted answer, it's always better to give min-response-size as well to remove server overhead of compressing all responses and also the the mime-types.

server.compression.enabled=true
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml
server.compression.min-response-size=2KB
like image 20
false9striker Avatar answered Nov 24 '25 07:11

false9striker



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!