I have a spring-boot/netty application setup to serve some static file from main/resource/static
. The application is also setup for compression.
server:
compression:
enabled: true
mime-types: application/geo+json, application/geo+json-seq, text/html, text/xml, text/plain, text/css, text/javascript, application/javascript, application/json, image/jpeg, application/vnd.geo+json
min-response-size: 2KB
One of the files is World_Countries_Boundaries.geojson
which is roughly 10MB and contains country boundaries.
The goal is to get this file gzip encoded.
This file should be considered application/geo+json
but the response header shows application/octet-stream
. It should also be gzip encoded.
How can I get this file to compress? My first thought was that spring is not resolving the mime-type correctly. This let me to an answer here. But this answer is only for a servlet container. My application is using netty. So I tried the netty factory.
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.server.MimeMappings;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CustomMimeMappings implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
@Override
public void customize(NettyReactiveWebServerFactory factory) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("geojson", "application/geo+json");
factory.setMimeMappings(mappings);
}
}
This solution does not compile because the netty factory does not have a setMimeMappings
method. This is where I am stuck.
How do I configure the application to correctly resolve the mime-type and compress this geojson file?